1
Fork 0
mirror of https://github.com/Steffo99/octogem.git synced 2024-11-22 04:54:18 +00:00
octogem/Assets/Scripts/Components/UnitHealth.cs

51 lines
1,009 B
C#
Raw Normal View History

2018-09-26 22:38:49 +00:00
using UnityEngine;
public class UnitHealth : MonoBehaviour
{
public int currentHealth;
public int maximumHealth = 10;
2018-09-30 14:35:17 +00:00
void Awake()
2018-09-26 22:38:49 +00:00
{
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;
}
}
}
}