using System; public class PlayerStateModel : IDisposable { public Health PlayerHealthComponent; public Player PlayerComponent; public event Action OnUpdate; public PlayerStateModel(Player player, Health playerHealth) { PlayerComponent = player; PlayerHealthComponent = playerHealth; PlayerHealthComponent.HealthChanged += HealthChangedHandler; } public void HealthChangedHandler(float newHp) { OnUpdate?.Invoke(this); } public void Dispose() { if (PlayerHealthComponent != null) PlayerHealthComponent.HealthChanged -= HealthChangedHandler; } }