Esempio n. 1
0
    bool CheckForBackstab(Action slot)
    {
        if (!slot.canBackstab)
        {
            return(false);
        }

        EnemyStates backstabTarget = null;

        Vector3 origin = transform.position;

        origin.y += 1;
        Vector3    rayDir = transform.forward;
        RaycastHit hit;

        if (Physics.Raycast(origin, rayDir, out hit, 3, ignoreLayers))
        {
            backstabTarget = hit.transform.GetComponentInParent <EnemyStates>();
        }

        if (backstabTarget == null)
        {
            return(false);
        }

        Vector3 dir = transform.position - backstabTarget.transform.position;

        dir.Normalize();
        dir.y = 0;
        float angle = Vector3.Angle(backstabTarget.transform.forward, dir);

        if (angle > 150)
        {
            Vector3 targetPos = dir * backstabOffset;
            targetPos         += backstabTarget.transform.position;
            transform.position = targetPos;

            backstabTarget.transform.rotation = transform.rotation;
            backstabTarget.IsGettingBackstabbed(slot, inventoryManager.GetCurrentWeapon(slot.mirror));

            onEmpty   = false;
            canAttack = false;
            canMove   = false;
            inAction  = true;
            anim.SetBool(StaticStrings.mirror, slot.mirror);
            anim.CrossFade(StaticStrings.parry_attack, 0.2f);
            lockonTarget = null;
            return(true);
        }

        return(false);
    }