Пример #1
0
 public void TakeDamage(float damage)
 {
     _health -= damage;
     OnPlayerHealthChangedEvent?.Invoke(_health / _maxHealth);
     if (_health <= 0)
     {
         Died?.Invoke(gameObject);
         ChangeScore?.Invoke();
     }
 }
    IEnumerator TakeDamageCoroutine(int damage, Vector2 kbDir, float kbVel)
    {
        yield return(new WaitForSeconds(0.05f));

        CineMachineImpulseManager.instance.Impulse(kbDir.normalized * 7);
        Audio.instance.playHurt();
        base.TakeDamage(damage, kbDir, kbVel);
        if (damage > 0)
        {
            OnPlayerDamagedEvent?.Invoke();
        }
        if (damage != 0)
        {
            OnPlayerHealthChangedEvent?.Invoke();
        }
        if (health > maxHealth)
        {
            health = maxHealth;
        }
    }