From 8306187e342d80179dfb390bb0a3ed9a55491b47 Mon Sep 17 00:00:00 2001 From: Liam Tolbert Date: Thu, 10 Oct 2024 20:09:52 -0400 Subject: [PATCH] finished up basic health for player --- .../Health/Runtime/PlayerHealthHandler.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Assets/ZombieCrossing/Scripts/ZombieCrossing/Health/Runtime/PlayerHealthHandler.cs b/Assets/ZombieCrossing/Scripts/ZombieCrossing/Health/Runtime/PlayerHealthHandler.cs index 72a85e3e..b09e71c9 100644 --- a/Assets/ZombieCrossing/Scripts/ZombieCrossing/Health/Runtime/PlayerHealthHandler.cs +++ b/Assets/ZombieCrossing/Scripts/ZombieCrossing/Health/Runtime/PlayerHealthHandler.cs @@ -14,6 +14,7 @@ public class PlayerHealthHandler : MonoBehaviour /// [SerializeField] private float health; + private bool IsDead = false; private bool HasTakenDamage = false; private float IFramesTimer = 0.0f; @@ -27,7 +28,7 @@ void Start() // Update is called once per frame void Update() { - if (health <= 0.0f) + if (health <= 0.0f && !IsDead) { die(); } @@ -38,16 +39,18 @@ void Update() if (IFramesTimer >= IFramesTime) { HasTakenDamage = false; + IFramesTimer = 0.0f;// reset iframes timer } } } - private void dealDamage(float damageDealt) + private void takeDamage(float damageDealt) { health -= damageDealt; + HasTakenDamage = true; healthEventChannel.HandlePlayerHit(); - Debug.Log("Oof! I took damage at " + Time.time); + Debug.Log(gameObject.name + " took" + damageDealt + " damage at " + Time.time); } @@ -55,16 +58,16 @@ private void die() { health = 0.0f; // do stuff to die + IsDead = true; healthEventChannel.HandlePlayerDeath(); - Debug.Log("Oh no! I died!"); + Debug.Log(gameObject.name + " died."); } private void OnControllerColliderHit(ControllerColliderHit hit) { - if (hit.gameObject.CompareTag("enemy"))// && !HasTakenDamage) + if (hit.gameObject.CompareTag("enemy") && !HasTakenDamage && !IsDead) { - dealDamage(1.0f);/// some enemy.damage value - + takeDamage(1.0f);// some enemy.damage value } } }