using TMPro; using UnityEngine; public class Vitals : MonoBehaviour { [SerializeField] private float initHealth = 100; [SerializeField] private GameObject canvas; [SerializeField] private GameObject damagePrefab; 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) { //hit } else { //heal } health += value; } } // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { health = initHealth; } }