Skip to content

Commit

Permalink
finished up basic health for player
Browse files Browse the repository at this point in the history
  • Loading branch information
liam-tolbert committed Oct 11, 2024
1 parent a8b8922 commit 8306187
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class PlayerHealthHandler : MonoBehaviour
/// </summary>
[SerializeField]
private float health;

private bool IsDead = false;
private bool HasTakenDamage = false;
private float IFramesTimer = 0.0f;
Expand All @@ -27,7 +28,7 @@ void Start()
// Update is called once per frame
void Update()
{
if (health <= 0.0f)
if (health <= 0.0f && !IsDead)
{
die();
}
Expand All @@ -38,33 +39,35 @@ 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);

}

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
}
}
}

0 comments on commit 8306187

Please sign in to comment.