Example #1
0
    }     // chase

    void Attack()
    {
        navmesh_Agent.velocity  = Vector3.zero;
        navmesh_Agent.isStopped = true;

        attack_Timer += Time.deltaTime;

        if (attack_Timer > wait_Before_Attack)
        {
            //转向玩家
            Vector3 relativePos = target.position - transform.position;
            float   angle       = Vector3.Angle(relativePos, transform.forward);
            if (angle > viewAngle / 2)
            {
                Quaternion rotation = Quaternion.LookRotation(relativePos, Vector3.up);
                transform.rotation = rotation;
            }

            enermy_Animator.Attack();

            attack_Timer = 0f;

            // play attack sound
            enermyAudio.Play_AttackSound();
        }

        if (Vector3.Distance(transform.position, target.position) >
            attack_Distance + chase_After_Attack_Distance)
        {
            Enermy_State = EnermyState.CHASE;
        }
    } // attack