using UnityEngine; using System; public class PlayerStats : MonoBehaviour { public static PlayerStats Instance; public float MaxTotalHealth = 10f; // Total number of heart containers that can ever be shown public float MaxHealth = 5f; // Current number of *active* hearts public float Health = 5f; // Current actual health public Action onHealthChangedCallback; private void Awake() { if (Instance == null) { Instance = this; } else { Destroy(gameObject); } } public void AddHealth() { if (MaxHealth < MaxTotalHealth) { MaxHealth += 1f; Health = MaxHealth; onHealthChangedCallback?.Invoke(); } } public void Heal(float amount) { Health = Mathf.Clamp(Health + amount, 0, MaxHealth); onHealthChangedCallback?.Invoke(); } public void TakeDamage(float amount) { Health = Mathf.Clamp(Health - amount, 0, MaxHealth); onHealthChangedCallback?.Invoke(); if (Health <= 0) { Debug.Log("Player died."); } } }