Example #1
0
    public void TakeDamage(int damageTaken)
    {
        if (currentShield > 0)
        {
            int shld = currentShield;
            currentShield -= damageTaken;
            if (currentShield < 0)
            {
                int carryoverDamage = currentShield;
                currentHP += carryoverDamage; //any negative shield is carried over as HP damage
                DamageNumber?.Invoke(shld, DmgNumbers.shieldDamageColor);
                if (carryoverDamage != 0)
                {
                    DamageNumber?.Invoke(-1 * carryoverDamage, DmgNumbers.damageColor);
                }
                currentShield = 0;
            }
            else
            {
                DamageNumber?.Invoke(damageTaken, DmgNumbers.shieldDamageColor);
            }
        }
        else
        {
            currentHP -= damageTaken;
            DamageNumber?.Invoke(damageTaken, DmgNumbers.damageColor);
        }

        if (currentHP <= 0)
        {
            HighScore highScore = FindObjectOfType <HighScore>();
            highScore.IncreaseHighScore();
            Die?.Invoke();
        }
        EnemyUIUpdate?.Invoke();
    }