Esempio n. 1
0
 private void HealthChanged(float prevHitPoints, float nextHitPoints)
 {
     if (Mathf.Approximately(nextHitPoints, 0f))
     {
         OnHealthZero.Invoke(prevHitPoints, 0f);
     }
     else if (Mathf.Approximately(nextHitPoints, hitPoints))
     {
         OnHealthFull.Invoke(prevHitPoints, hitPoints);
     }
     else
     {
         OnHealthChanged.Invoke(prevHitPoints, nextHitPoints);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Lose health. The health loss is never more than zero
        /// </summary>
        /// <param name="value"></param>
        public void LoseHealth(Attack attack)
        {
            if (health - attack.value < 0)
            {
                attack.value = health;
            }

            health -= attack.value;
            OnHealthChanged?.Invoke(attack);

            // In the case of the health going down to zero
            if (health <= 0)
            {
                OnHealthZero?.Invoke(attack.owner);
            }
        }
Esempio n. 3
0
    public void Damage(int damage)
    {
        if (_health - damage >= 0)
        {
            _health -= damage;
        }
        else
        {
            _health = 0;
        }
        OnHealthChanges?.Invoke(this, EventArgs.Empty);

        if (_health == 0)
        {
            OnHealthZero?.Invoke(this, EventArgs.Empty);
        }
    }