Files
CastleDefence/Assets/Scripts/Building.cs

38 lines
836 B
C#
Raw Normal View History

2026-04-01 15:46:15 +01:00
using UnityEngine;
using UnityEngine.UI;
public class Building : MonoBehaviour
{
public float maxHealth;
private float curHealth;
private Slider healthBar;
void Awake()
{
healthBar = GetComponentInChildren<Slider>();
}
// 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;
}
}