public GameObject player;
void Update () {
Vector3 playerPos = player.transform.position;
float distance = Vector3.Distance(transform.position, playerPos);
float angle = Vector3.Angle(transform.forward.normalized,(target.position - transform.position).normalized);
if (distance <= 2f && angle<30)
{
agent.ResetPath();
transform.LookAt(player.transform.position);
Debug.Log("攻击玩家");
}
else if (distance <= 5f)
{
Debug.Log("追踪玩家");
f = true;
nav.destination = player.transform.position;
}
else
{
Debug.Log("继续巡逻");
Patrol();
}
}
void Patrol()
{
timer += Time.deltaTime;
if (timer >= waitTimer)
{
index++;
index %= 4;
timer = 0;
Debug.Log(index);
nav.destination = waypoints[index].position;
}
}