Esempio n. 1
0
    // Reduces health, disables the enemy that hit the hero,
    // and invokes an event if the health reaches zero
    private void ReduceHealth(GameObject enemyThatHitHero)
    {
        enemyThatHitHero.SetActive(false);

        health--;

        if (health <= 0)
        {
            HealthReachedZero?.Invoke();
        }
    }
Esempio n. 2
0
    public virtual void TakeDamage(int value)
    {
        if (health == null)
        {
            return;
        }

        health.value = Mathf.Clamp(health.value - value, 0, maxHealth.value);
        if (health.value == 0)
        {
            HealthReachedZero?.Invoke(this);
            Die();
        }
    }