Vector3.Lerp Only working once

I’m trying to make a very simple AI script. All I want the enemy to do is travel to its target when a variable is no longer checked. When the game starts everything works how its supposed to, however when the variable is checked and the enemy waits (This gives the “player” a chance to move away). The next time the variable is unchecked, instead of traveling to the target like it did the first time, it instantly transports itself to the targets location. Any ideas on why this is happening?

var duration : int = 3;

var start : Transform;

var end : Transform;

var waiting : boolean = false;

var targetObj : GameObject;

private var targetScript : Target;

function Awake (){														

targetScript = targetObj.GetComponent(Target);


function Update(){

	if(waiting == false){

		transform.position = Vector3.Lerp(start.position, end.position, Time.time/duration);



It works the first time because Time.time starts at 0. After that , it’s going to be bigger than 1.

You need the last parameter of the Lerp to be a number between 0 and 1 - if it’s 0 it’s at the start position and 1 it’s at the end position.

You would normally add Time.deltaTime to something to calculate it:

   var t : Float = 0;
   t += time.deltaTime;
   transform.position = Vector3.Lerp(start.position, end.position, t/duration);

And reset t when you want to start again.