Initial commit
This commit is contained in:
41
Assets/Scripts/PlayerHealth.cs
Normal file
41
Assets/Scripts/PlayerHealth.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerHealth : MonoBehaviour
|
||||
{
|
||||
public int maxHealth = 100;
|
||||
private int currentHealth;
|
||||
|
||||
void Start()
|
||||
{
|
||||
currentHealth = maxHealth;
|
||||
// Force the UI to update on frame 1
|
||||
UIManager.Instance.UpdatePlayerHealth(currentHealth, maxHealth);
|
||||
}
|
||||
|
||||
public void TakeDamage(int damage)
|
||||
{
|
||||
currentHealth -= damage;
|
||||
currentHealth = Mathf.Max(0, currentHealth); // Prevent negative health
|
||||
|
||||
UIManager.Instance.UpdatePlayerHealth(currentHealth, maxHealth);
|
||||
|
||||
if (currentHealth <= 0)
|
||||
{
|
||||
Die();
|
||||
}
|
||||
}
|
||||
|
||||
private void Die()
|
||||
{
|
||||
Debug.Log("<color=red>Player has fallen! The horde wins.</color>");
|
||||
// TODO: Trigger player death animation and game over screen
|
||||
}
|
||||
public void Heal(int amount)
|
||||
{
|
||||
currentHealth += amount;
|
||||
currentHealth = Mathf.Min(currentHealth, maxHealth); // Prevent overhealing
|
||||
|
||||
UIManager.Instance.UpdatePlayerHealth(currentHealth, maxHealth);
|
||||
Debug.Log($"<color=green>Player Healed for {amount}!</color>");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user