I’m trying to transform the position of an object once a variable in another script becomes true, but of course, it doesn’t work properly, it starts from position B once the variable (csScript.wave) becomes true. Here is my code;
var pointB : Vector3;
var pointC : Vector3;
var pointD : Vector3;
var pointE : Vector3;
var pointF : Vector3;
var csScript : TargetCollision;
// private var endPos : Vector3 = new Vector3(0.0, 40.0, 0.0);
function Start () {
//animation.Play("running");
var pointA = transform.position;
while (true) {
//while(csScript.wave){
//if(csScript.wave){
yield MoveObject(transform, pointA, pointB, 3.0);
yield MoveObject(transform, pointB, pointC, 3.0);
yield MoveObject(transform, pointC, pointD, 3.0);
yield MoveObject(transform, pointD, pointE, 3.0);
yield MoveObject(transform, pointE, pointF, 3.0);
// }
}
}
function MoveObject (thisTransform : Transform, startPos : Vector3, endPos : Vector3 , time : float) {
if(csScript.wave){
transform.position = startPos;
transform.LookAt(endPos);
var i = 0.0;
var rate = 1.0/time;
while (i < 1.0) {
i += Time.deltaTime * rate/8;
// if(csScript.wave)
thisTransform.position = Vector3.Lerp(startPos, endPos, i);
yield;
}
}
}