using Creatures; using TMPro; using Unity.VisualScripting; using UnityEngine; public class Vitals : MonoBehaviour { [SerializeField] private float initHealth = 100; [SerializeField] private GameObject canvas; [SerializeField] private GameObject damagePrefab; private IVitalReaction _reaction; private float health; public float Health { get { return health; } set { GameObject damageInstance = Instantiate(damagePrefab, canvas.transform); damageInstance.transform.localPosition = Vector3.zero; damageInstance.GetComponent().SetText(Mathf.Abs((int)value).ToString()); if (value < 0) { _reaction.Hit(); } else { _reaction.Heal(); } health += value; } } // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { health = initHealth; } void OnEnable() { _reaction = GetComponent(); } }