示例#1
0
    public void TakeDamange(int damage)
    {
        if (!canTakeDamage)
        {
            return;
        }

        currentHealth -= damage;
        currentHealth  = Mathf.Clamp(currentHealth, 0, MaxHealth);

        UpdateHealthBar();

        if (enemy != null)
        {
            enemy.ActivateTookDamage();
        }

        if (currentHealth <= 0)
        {
            if (player != null)
            {
                player.KillPlayer();
            }
            else if (enemy != null)
            {
                enemy.KillMe();
            }
        }
    }