namespace Code.Gameplay.Player { public class PlayerHealth { public delegate void OnDeathDelegate(); public event OnDeathDelegate OnDeath; public delegate void OnDamageDelegate(int damage, PlayerHealth health); public event OnDamageDelegate OnDamage; private int _healthPoints; public int HealthPoints => _healthPoints; public int MaxHealthPoints { get; private set; } public void GetDamage(int count) { _healthPoints -= count; OnDamage?.Invoke(count, this); if (_healthPoints <= 0) OnDeath?.Invoke(); } public PlayerHealth(int maxHealthPoints = 1) { _healthPoints = maxHealthPoints; MaxHealthPoints = maxHealthPoints; } public void InstaKill() { _healthPoints = 0; OnDeath?.Invoke(); } } }