//巡逻
private void Patrolling()
{
if (navMeshAgent.remainingDistance<0.8f)
{
Debug.Log("navMeshAgent.destination" + navMeshAgent.destination);
navMeshAgent.Stop();
patrolTimer += Time.deltaTime;
Debug.Log(patrolTimer);
if (patrolTimer>patrolTime)
{
index++;
index %= 4;
Debug.Log("Time"+Time.deltaTime);
Debug.Log("index" +index);
navMeshAgent.destination = wayPoint[index].position;
Debug.Log("Time***********" + Time.deltaTime);
patrolTimer = 0;
Debug.Log("navMeshAgent.destination" + navMeshAgent.destination);
}
}
}
index1
Time***********0.04596787
navMeshAgent.destination(-25.7, 0.0, 7.2)
机器人走到第一个路标就不动了,找半天找不到问题...按照视频码的啊
目标坐标也更新到第二个路标了,机器人就是不动啊。timer归零后就不动了。没有循环起来啊。是不是我在面板上哪里没设置好?navMeshAgent 没介绍过
private void Patrolling()
{
if (navMeshAgent.remainingDistance<0.8f)
{
navMeshAgent.Stop();
patrolTimer += Time.deltaTime;
if (patrolTimer>patrolTime)
{
index++;
index %= 4;
navMeshAgent.destination = wayPoint[index].position;
patrolTimer = 0;
}
}
Debug.Log("sssssssssss");
navMeshAgent.destination = wayPoint[index].position;
一直在输出ssssssssssssss
public float twoTime = 2;
private float timer = 0;
public Transform[] ZuoBiao;
private int idex = 0;
private NavMeshAgent navAgent;
void Awake()
{
navAgent = this.GetComponent<NavMeshAgent>();
}
void Update () {
if (GameController._instance.alarmLight==false)
{
patrolling();
}
}
//巡逻
private void patrolling()
{
if (navAgent.remainingDistance > 0.5f)
{
navAgent.destination = ZuoBiao[idex].position;
}
else
{
timer += Time.deltaTime;
if (timer>=twoTime)
{
idex++;
timer = 0;
if (idex > 3)
{
idex = 0;
}
navAgent.destination = ZuoBiao[idex].position;
}
}
}
我重新自己写了代码(我靠,我第一个自己的脚本啊,哭),按照自己的想法重新写了,问题解决了。我猜可能是NavMeshAgent.Stop()方法改了,我用的是5.3的版本。这个stop一调用整个导航就停了不动了。我改的是让npc停在原地读秒,读够数才能去下一个点。