1
Fork 0
mirror of https://github.com/Steffo99/octogem.git synced 2024-11-21 20:44:19 +00:00
octogem/Assets/Scripts/Components/UnitHealth.cs

50 lines
1,009 B
C#

using UnityEngine;
public class UnitHealth : MonoBehaviour
{
public int currentHealth;
public int maximumHealth = 10;
void Awake()
{
currentHealth = maximumHealth;
}
public void Damage(int amount)
{
//Negative damage doesn't exist
if(amount <= 0)
{
return;
}
//Damage the unit
currentHealth -= amount;
//Do not go beyond zero
if(currentHealth < 0)
{
currentHealth = 0;
}
}
public void Heal(int amount)
{
currentHealth += amount;
//Positive healing
if (amount >= 0)
{
if(currentHealth > maximumHealth)
{
currentHealth = maximumHealth;
}
}
//Negative healing: non-lethal!
else
{
//Prevent lethal damage
if(currentHealth <= 0)
{
currentHealth = 1;
}
}
}
}