mirror of
https://github.com/Steffo99/mission-failed.git
synced 2024-12-04 22:04:17 +00:00
52 lines
1.1 KiB
C#
52 lines
1.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class HealthController : MonoBehaviour {
|
|
public int currentHealth;
|
|
public int maximumHealth = 1;
|
|
|
|
void Start()
|
|
{
|
|
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;
|
|
BroadcastMessage("Die");
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|