public Transform[] wayPoints;
private int index = 0;
private NavMeshAgent navAgent;
private float patrolWaitTime=3f;
private float patrolWaitTimer=0;
// Use this for initialization
void Awake () {
navAgent = GetComponent<NavMeshAgent>();
navAgent.destination = wayPoints[index].position;
navAgent.updatePosition = false;
navAgent.updateRotation = false;
}
private void Patrolling()
{
navAgent.speed = 2.5f;
navAgent.destination = wayPoints[index].position;
navAgent.updatePosition = false;
navAgent.updateRotation = false;
if (navAgent.remainingDistance<0.5f)
{
patrolWaitTimer += Time.deltaTime;
if (patrolWaitTimer>patrolWaitTime)
{
index++;
index %=wayPoints.Length;
navAgent.destination = wayPoints[index].position;
navAgent.updatePosition = false;
navAgent.updateRotation = false;
patrolWaitTimer = 0;
}
}
}
秘密行动第33课,控制机器人行走动画,代码是跟老师一样的,但是我运行的时候机器人总是模型与NavMesh分离了,请教是哪里出了问题?