Пример #1
0
    public void TakeDamage(Spell spell)
    {
        if (!spell.EnemyHit)
        {
            Vector2 damageTextPos = new Vector2(this.transform.position.x, this.transform.position.y + 2);
            if (spell.SpellDamageType == _weakness)
            {
                //if the damage type of the spell is the same as the weakness of the enemy, do double damage
                _currentHealth -= spell.SpellDamage * 2;
                ShowDamage.onShowDamage(damageTextPos, spell.SpellDamage * 2, true);
                ScreenShake.onScreenShake(4);
            }
            else
            {
                //IF the spells damage type is not the same as the weakness of the enemy, deal normal damage
                _currentHealth -= spell.SpellDamage;
                ShowDamage.onShowDamage(damageTextPos, spell.SpellDamage, false);
                ScreenShake.onScreenShake(1);
            }
            spell.EnemyHit = true; //This is to make sure spells dont hit multiple enemies
            StartCoroutine(TakeDamageRoutine(0.3f));
        }

        _healthbar.ChangeHealth(_currentHealth, _maxHealth);
        if (_currentHealth <= 0)
        {
            Death();
        }
    }