26 lines
656 B
C#
26 lines
656 B
C#
using UnityEngine;
|
|
|
|
namespace Code.Example.Platformer.Entity
|
|
{
|
|
public class EntityHealth : MonoBehaviour
|
|
{
|
|
private int _health;
|
|
private int _maxHealth;
|
|
public void SetMaxHealth(int maxHealth) => _maxHealth = maxHealth;
|
|
public bool IsDead { get; private set; }
|
|
|
|
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;
|
|
}
|
|
}
|
|
} |