Exemplo n.º 1
0
 public void Update(GameTime gameTime)
 {
     if (Health.Current <= 0)
     {
         DeathStrategy.Die(this);
     }
 }
Exemplo n.º 2
0
    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();
    }
Exemplo n.º 3
0
    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);
        }
    }