目录
45、Navmesh路径
更新PlayerBot.cs
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using Random = UnityEngine.Random;
public class PlayerBot : Player
{
……
void FixedUpdate()
{
if (isDead) return;
if (inRange.Count == 0)
{
if (Vector3.Distance(transform.position, targetPoint) < agent.stoppingDistance)
{
RandomPoint(transform.position, range * 3, out targetPoint);
}
}
else
{
if (Vector3.Distance(transform.position, targetPoint) < agent.stoppingDistance)
{
RandomPoint(inRange[0].transform.position, range * 2, out targetPoint);
}
for (int i = 0; i < inRange.Count