public void Update(GameTime gameTime) { if (Health.Current <= 0) { DeathStrategy.Die(this); } }
public virtual void Die() { //Notify all listeners about the death OnObjectDeath.Invoke(); deathStrategy.Die(gameObject); //Clear all listeners for reusability of the object in the pool OnHealthChanged.RemoveAllListeners(); OnObjectDeath.RemoveAllListeners(); }
void OnTriggerEnter2D(Collider2D other) { //If we hit active game objects (world, enemy, player) if (!other.CompareTag("Untagged")) { deathStrategy.Die(gameObject); } //If we hit an object with health Health targetHealth = other.gameObject.GetComponent <Health>(); if (targetHealth) { targetHealth.ApplyDamage(Damage); } }