using UnityEngine; namespace Player { public class PlayerVitalsSystem : MonoBehaviour { public static PlayerVitalsSystem Instance { get; private set; } [Header("Vitals")] public VitalStat health = new VitalStat(); public VitalStat hunger = new VitalStat(); public VitalStat sanity = new VitalStat(); public VitalStat thirst => health; [Header("Runtime")] public bool runDecay = true; void Reset() { if (string.IsNullOrWhiteSpace(health.id)) health.id = "health"; if (string.IsNullOrWhiteSpace(hunger.id)) hunger.id = "hunger"; if (string.IsNullOrWhiteSpace(sanity.id)) sanity.id = "sanity"; } void Awake() { if (Instance != null && Instance != this) { Destroy(gameObject); return; } Instance = this; if (string.IsNullOrWhiteSpace(health.id)) health.id = "health"; if (string.IsNullOrWhiteSpace(hunger.id)) hunger.id = "hunger"; if (string.IsNullOrWhiteSpace(sanity.id)) sanity.id = "sanity"; health.Initialize(invokeEvents: true); hunger.Initialize(invokeEvents: true); sanity.Initialize(invokeEvents: true); } void Update() { if (!runDecay) return; float dt = Time.deltaTime; health.Tick(dt); hunger.Tick(dt); sanity.Tick(dt); } public void ApplyDelta(float thirstDelta, float hungerDelta, float sanityDelta) { if (thirstDelta != 0f) health.Add(thirstDelta); if (hungerDelta != 0f) hunger.Add(hungerDelta); if (sanityDelta != 0f) sanity.Add(sanityDelta); } public void AddHealth(float delta) => health.Add(delta); public void AddHunger(float delta) => hunger.Add(delta); public void AddSanity(float delta) => sanity.Add(delta); } }