I m having a hard time for a few days allready figuring out how to execute multiple
iTween.MoveTo functions.
Basically, i need my script to wait for the iTween.MoveTo to finish moving and then proceede to next stuff.
Simple example:
iTween.MoveTo(tile.gameObject, iTween.Hash("position", destination1, "time", 2f));
//now here script has to wait until upper iTween.MoveTo finishes moving
iTween.MoveTo(tile.gameObject, iTween.Hash("position", destination2, "time", 2f));
In this case, second iTween.MoveTo “kills” first one and only second one is executed.
I tryed to make it with delay property of iTween.MoveTo, but then other kind of problems occur, i.e. MoveTo waits but gets wrong destination point since destination is
calculated too early. I tryed with yield but no results, i dont understand that concept quite well.
Anway, i need my script to wait (not completely freeze) until iTween.MoveTo finishes, how could i do it, maybe make a separate thread and then stop one until other finishes or… ?
Now there are ways you can improve this, for instance don’t wait on discrete periods of time, I’m not sure offhand if iTween provides some object you can check to see when an action is done but this might be best, or you could even check the distance between the current location and the target location and continuing once you get to approximately 0.
Have a look at coroutines. I haven’t used them myself enough to have more specific advice, but you can make coroutines pause for a certain amount of time, or until another coroutine has completed.
If you look at the iTween documentation there is a field in the Hash values called “oncomplete”. This is a string that is the name of a function to call when the iTween finishes. So just move your code to finish and next iTween call to a separate method and place that method name as the value to “oncomplete”. Saves all the extra steps with setting up a coroutine.