28 lines
672 B
C#
28 lines
672 B
C#
using System;
|
|
public class PlayerStateModel : IDisposable
|
|
{
|
|
public Health PlayerHealthComponent;
|
|
public Player PlayerComponent;
|
|
|
|
public event Action<PlayerStateModel> 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;
|
|
}
|
|
}
|