using UnityEngine;
namespace BehaviorDesigner.Runtime.Tactical
{
///
/// Example component which adds health to an object.
///
public class Health : MonoBehaviour, IDamageable
{
// The amount of health to begin with
public float startHealth = 100;
private float currentHealth;
///
/// Initailzies the current health.
///
private void Awake()
{
currentHealth = startHealth;
}
///
/// Take damage. Deactivate if the amount of remaining health is 0.
///
///
public void Damage(float amount)
{
currentHealth = Mathf.Max(currentHealth - amount, 0);
if (currentHealth == 0) {
gameObject.SetActive(false);
}
}
// Is the object alive?
public bool IsAlive()
{
return currentHealth > 0;
}
///
/// Sets the current health to the starting health and enables the object.
///
public void ResetHealth()
{
currentHealth = startHealth;
gameObject.SetActive(true);
}
}
}