public class EnemyMoveAI : MonoBehaviour {
public Transform[] wayPoints;
public float patrolTime = 3f;
private int index = 0;
private float patrolTimer = 0;
private NavMeshAgent navAgent;
void Awake()
{
navAgent = GetComponent<NavMeshAgent>();
navAgent.destination = wayPoints[index].position;
}
// Update is called once per frame
void Update () {
Patrolling();
}
private void Patrolling()
{
if (navAgent.remainingDistance < 0.5f)
{
navAgent.isStopped = true;
patrolTimer += Time.deltaTime;
if (patrolTimer > patrolTime)
{
index++;
index %= 4;
navAgent.destination = wayPoints[index].position;
patrolTimer = 0;
}
}
}
}
这边目的地也赋值了
同学你好,单看这一个脚本是没问题的,老师感觉只寻找第一个点之后不去寻找应该是满足了移动条件或者停止了,同学可以下载一下老师的源码对比看一下,也可以自己Debug一下,看看我们代码哪里出了问题。