using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; /// /// Link zum OG Script: https://www.youtube.com/watch?v=vNL4WYgvwd8 /// 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().UpdateHighScore(); spawnScanner.GetComponent().stopSpawn(); spawnScanner.GetComponent().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 } } }