54 lines
1.2 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
/// <summary>
/// Link zum OG Script: https://www.youtube.com/watch?v=vNL4WYgvwd8
/// </summary>
public class Health : MonoBehaviour
{
public int maxHealth = 5;
public int currentHealth = 5;
public Image healthbar;
public GameObject spawnScanner;
public bool noRepeat = true;
// health logic
void Start()
{
currentHealth = maxHealth;
}
// take dmg logic
private void Update()
{
HeightDeathZone();
TakeDamage();
}
private void HeightDeathZone()
{
if (transform.position.y <= -5 && noRepeat)
{
noRepeat = false;
GetComponent<PlayerScore>().UpdateHighScore();
spawnScanner.GetComponent<SpawnScanner>().stopSpawn();
spawnScanner.GetComponent<BoxCollider2D>().enabled = false;
SceneManager.LoadSceneAsync("MenuScene");
}
}
void TakeDamage()
{
// code from Christian
healthbar.fillAmount = (float)currentHealth / (float)maxHealth;
if (currentHealth <= 0)
{
// player is dead
// death animation
// game over screen
}
}
}