I've a character that walks from waypoint 0 to 1 from 1 to 2 from 2 to 3. the character reaches from 0 to 1 it waits 1.5 seconds, and then when it gets to the 2nd waypoint it doesn't wait 1.5 seconds, and so on..
http://09duck.pastebin.com/qVREn4NB
var waypoint : Transform[];
var speed : float = 3;
var currentWaypoint : int;
var loop = true;
var test;
function Update () {
animation.wrapMode = WrapMode.Loop;
var controller : CharacterController = GetComponent(CharacterController);
if(currentWaypoint < waypoint.length){
var target : Vector3 = waypoint[currentWaypoint].position;
var moveDirection : Vector3 = target - transform.position;
if(moveDirection.magnitude <= 1.5){
print("magniute");
animation.CrossFade("idle");
speed = 0;
WaitThreeSeconds();
if(test){
test = false;
currentWaypoint++;
}
if(currentWaypoint == 3){ currentWaypoint -= 3; }
}
else{
animation.CrossFade("walk");
speed = Random.Range(0.8,2.01);
RotateTowards();
}
}
//print(moveDirection.magnitude);
controller.SimpleMove(moveDirection.normalized * speed);
}
function RotateTowards () {
var target : Vector3 = waypoint[currentWaypoint].position;
var moveDirection : Vector3 = target - transform.position;
while(Vector3.Distance(target, transform.position) >= 1.5){
transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(moveDirection), 0.5* Time.deltaTime);
transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);
yield;
}
}
function WaitThreeSeconds(){
yield WaitForSeconds(1.5);
test = true;
}