Files
Infratest/Assets/Code/Example/Platformer/Entity/EntityHealth.cs
T

27 lines
638 B
C#

namespace Code.Example.Platformer.Entity
{
public class EntityHealth
{
private int _health, _maxHealth;
public bool IsDead { get; private set; }
public EntityHealth(int initialHealth)
{
_health = initialHealth;
}
public void GiveDamage(int damage)
{
_health -= damage;
if(_health <= 0) IsDead = true;
}
public void Heal(int heal)
{
if (IsDead) return;
if (_health + heal > _maxHealth) _health = _maxHealth;
else _health += heal;
}
}
}