Stopping an iTween


My gameObject has a function attached to it containing a simple looping MoveTo iTween. It gets called by a Broadcasted message from a parent object. It also has a second function that contains an iTween.Stop(gameObject) command which gets called by the parent when a button is clicked. The function definitely executes (can tell with the debugger) but the iTween does not stop. I’ve looked at the documentation and added the WaitForSeconds command to to the function as well, but it still doesn’t seem to affect anything.

Any ideas? Thanks in advance.

You could try and just do iTween.Stop(); and see if it stops then… If it does, then the looping iTween event might for some reason not be on the same gameObject…

Also, how do you call the looping MoveTo? Because if you are calling it inside a function that e.g. is being called every frame, then iTween.Stop(gameObject); might be stopping it – but then it’s instantly getting invoked again…

You are right. The function was being called again right after the stop and I didn’t realize it! …how silly. Thank you for pointing that out!

PetterDK do you by any chance know how to restart the itween once you have used used iTween.Stop(); with new speed parameters?

Thanks In Advance

@Wheats – Again, please use the ‘comment’ option for anything else than an actual answer to a question!

To answer your question, an iTween is AFAIK to be seen as an event that fires once. With that in mind, your iTween can’t be restarted per se – just played again. E.g. if the iTween that you are using is a MoveTo, you can just execute a new iTween event.

iTween.Stop(); stops and destroys all tweens in the current scene, so to “restart” it you just execute the same line of code with a different speed value.

I think we need to add a WaitForSeconds(0.1f) right after stopping: