示例#1
0
    public void DamageObj(int dmg, EntityStatus sender)
    {
        if (status.invuln)
        {
            Debug.Log(gameObject.name + " Dodged");
            return;
        }
        else if (status.parry)
        {
            if (sender != null)
            {
                sender.GetComponent <Health>().DamageObj(dmg, GetComponent <EntityStatus>());
            }

            FindObjectOfType <FirstPersonRigTest>().ResetParry();

            Debug.Log(gameObject.name + " Parried");

            return;
        }
        else if (status.block)
        {
            dmg = Mathf.RoundToInt((float)dmg / 4);
            Debug.Log(gameObject.name + " Blocked");
        }
        else
        {
            Debug.Log(gameObject.name + " was hit");
        }

        if (currentShield > 0)
        {
            currentShield -= dmg;
            if (currentShield <= 0)
            {
                currentShield = 0;
            }

            Hurt?.Invoke(dmg);
        }
        else
        {
            currentHp -= dmg;
            if (currentHp <= 0)
            {
                currentHp = 0;
            }


            Hurt?.Invoke(dmg);
        }
        UpdateUI();

        shieldDelayTimer = shieldRechargeDelay;

        if (currentHp <= 0)
        {
            Die?.Invoke();
        }
    }