Esempio n. 1
0
    // Helper method to remove health from our health controller.
    public void LoseHealth(float health)
    {
        health -= health * (1.0f - (10.0f / (10.0f + defensePoints)));
        Debug.Log(name + " lost " + health + " hp.");
        this.health -= health;
        this.health  = Mathf.Max(this.health, 0.0f);

        if (loseHealthSFX && this.health > 0.0f)
        {
            switch (deathSFX)
            {
            case DeathSFX.NORMAL:
                AudioController.Hurt();
                break;

            case DeathSFX.EXPLODE:
                AudioController.ElectricalHurt();
                break;

            case DeathSFX.SHATTER:
                AudioController.CrystalHurt();
                break;
            }
        }
        if (spriteRenderer != null)
        {
            animationCoroutine = StartCoroutine(DamageAnimation());
        }
        if (healthBar != null)
        {
            healthBar.SetMainValue(this.health, maxHealth);
        }
        if (this.health == 0.0f)
        {
            Die();
        }
    }