- Home /
move a gameobject in steps according to list of times
I have two lists, one with times and another with positions they look like this:
times: 0.02, 0.07, 1.32 positions: (0,0,0),(1,0,2),(2,0,3)
How would you go about moving a gameobject from position to position at the specific times?
Solution (Thanks to MikeNewall):
void Update () {
if(readyMove && step < logObjects.Count-1)
MoveObjects();
}
private void MoveObjects() {
if (logObjects[step].RecTime < Time.time-startTime) {
step++;
NextStep();
}
}
private void NextStep() {
logObj.transform.position = logObjects[step].Pos;
logObj.transform.eulerAngles = logObjects[step].Rot;
}
Answer by MikeNewall · Apr 07, 2013 at 04:04 PM
You'll need to check the time since the game started against the times in the list. I'm assuming that the list order of times matches the order of positions you want to move to?
Check the current game time against the first time in the list, if it's greater than or equal to the list time then you move to its respective position, and remove both the time and position from their lists. Rinse and repeat :) Let me know if you need some code.
Thanks for the answer, that's an approach I haven't thought of! I'll see if I can make it work :)
Your answer
