Пример #1
0
    //Damage control.
    public void TakeDamage(int damage)
    {
        if (IsDead)
        {
            return;
        }

        dmgEffect.FadeIn();

        // Decrement the current health by the damage but make sure it stays between the min and max.
        CurrentHealth -= damage;
        CurrentHealth  = Mathf.Clamp(CurrentHealth, 0f, StartingHealth);

        // Set the health bar to show the normalised health amount.
        HealthBar.fillAmount = CurrentHealth / StartingHealth;

        // If the current health is approximately equal to zero
        if (Mathf.Abs(CurrentHealth) < float.Epsilon)
        {
            isDead = true;
            Wait(2);
        }
    }