private void TakeDamage(double amount, PlayerIdentifier shooter) { Debug.Log("Taking Damage"); if (amount >= Health) { Health = 0; KillThisUnit(shooter); } else { Health -= amount; HealthChangeHandler handler = EventHealthChanged; if (oem.shouldTriggerEvent(handler)) { Debug.Log("Triggering Health change event"); handler(Health); } } }
private void OnHealthChanged(int id, float value) { HealthChangeHandler?.Invoke(value, _stats[id].Max); }
// add a subscriber to the event public void AddHealthSubscriber(HealthChangeHandler healthHandler) { _healthChangeEvent += healthHandler; }
public void AddHealthChangeSubscriber(HealthChangeHandler healthChangeHandler) { _healthChangedEvent += healthChangeHandler; OnHealthChange(); }