Initial Commit
This commit is contained in:
37
Assets/Scripts/Building.cs
Normal file
37
Assets/Scripts/Building.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user