예제 #1
0
    public void TakeDamage(int damage, Thing owner)
    {
        if (dead)
        {
            return;
        }
        OnGetHit?.Invoke(owner);
        if (damage == 0 || CheckStackableBool <InvinsibleBuff>())
        {
            return;
        }
        damage = Mathf.Clamp(damage + owner.strength, 0, 10000);
        // if tmpShieldQueue
        if (shield > 0)
        {
            int dmgOnShield = Mathf.Min(shield, damage);
            shield -= dmgOnShield;
            damage -= dmgOnShield;
        }

        hp -= damage;
        if (damage > 0)
        {
            OnLoseHP?.Invoke(damage);
        }
        if (hp <= 0)
        {
            Die();
        }
    }
예제 #2
0
 public void TakeDamage(int damage)
 {
     if (invincible)
     {
         return;
     }
     if (invincibleDurAfterHit > 0f)
     {
         StartCoroutine(CancelInvincible());
     }
     health -= damage;
     OnLoseHP?.Invoke(damage);
     if (m_takeDamageAct != null)
     {
         m_takeDamageAct.Invoke(damage);
     }
     if (health <= 0)
     {
         thing.Die();
     }
     else
     {
         if (GetComponent <AudioSource>() != null)
         {
             GetComponent <AudioSource>().PlayOneShot(hitClip);
         }
     }
     StartCoroutine(OnHit());
 }