Skip to content

develop KnockBack

Yoo Hyeokjin edited this page Jun 25, 2023 · 8 revisions

KnockBack

목차

설명

Script

public void TakeDamage(float damage, int weaponIndex)
{
    mHealth -= damage;
    GameManager.instance.WeaponDamage[weaponIndex] += damage;

    if (mHealth > 0)
    {
        StartCoroutine(KnockBack());
        mAnim.SetTrigger("Hit");
        Debug.Log("Hit");
        if(weaponIndex == 6)
        {
            if(mKnockbackpower < 3)
            {
                mKnockbackpower++;
            }
        }
    }
    else
    {
        mbLive = false;
        mColl.enabled = false;
        mRb.simulated = false;
        mSpriter.sortingOrder = 1;
        mAnim.SetBool("Dead", true);
        GameManager.instance.Kill++;
        Dead();
        GameManager.instance.KillCount[weaponIndex]++;
    }
}
private IEnumerator KnockBack()
{
    yield return mWait;
    Vector3 playerPos = GameManager.instance.Player.transform.position;
    Vector3 dirVec = transform.position - playerPos;
    mRb.AddForce(dirVec.normalized * (3 + mKnockbackpower), ForceMode2D.Impulse);
}
Clone this wiki locally