By OnTriggerEnter on one of the triggers, it should make Target(s) move from a point to another and stop. Here’s the code:
for (ae = 0; ae < Target.Length; ae = ae + 1) {
Point_To_Move = Target[ae].position + MoveFromPos;
Target[ae].position = Vector3.Lerp (Target[ae].position, Point_To_Move, Speed * Time.deltaTime);
}
Point_To_Move will give the end position.
What can I do to solve this? Do I need to put it under a loop? If so, how?
Tried using a function with a loop. But no results.
for (ae = 0; ae < Target.Length; ae = ae + 1) {
Point_To_Move = Target[ae].position + MoveFromPos;
MoveObjectLerp(Target[ae].transform, Target[ae].position, Point_To_Move, Speed);
}
Later in the code:
function MoveObjectLerp (thisTransform : Transform, startPos : Vector3, endPos : Vector3, timem : float) {
var z = 0.0;
var rate = 1.0/timem;
while (z < 1.0) {
z += Time.deltaTime * rate;
thisTransform.position = Vector3.Lerp(startPos, endPos, z);
yield;
}
}