using UnityEngine; using UnityEngine.UI; public class Building : MonoBehaviour { public float maxHealth; private float curHealth; private Slider healthBar; void Awake() { healthBar = GetComponentInChildren(); } // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { curHealth = maxHealth; healthBar.maxValue = maxHealth; healthBar.value = curHealth; } // Update is called once per frame void Update() { } public void TakeDamage(float damageToTake) { curHealth -= damageToTake; if(curHealth <= 0) gameObject.SetActive(false); healthBar.value = curHealth; } public float GetHealth() { return curHealth; } }