I have an animation which plays in the Update
-function, in a Switch
case.
After the animation finishes, a Boolean is being set to true.
My code:
case "play":
animation.Play("play");
gobool = true;
startbool = false;
break;
The problem is my gobool
and startbool
get set immediately without finishing the animation. How can I let my program wait untill the animation is finished?
Basically you need to do two things for this solution to work:
An example of how this could be done is:
And the definition for
WaitForAnimation
would be:C#:
JS:
The do-while loop came from experiments that showed that the
animation.isPlaying
returnsfalse
in the same frame PlayQueued is called.With a little tinkering you can create a extension method for animation that simplifies this such as:
Finally you can easily use this in code:
Source, alternatives and discussion.