- Home /
The question is answered, right answer was accepted
Wait for a animation to finish in unity3d
I have a animation to play in update function in switch case.
after animation finish, a boolean get active
I written code as
case "play":
animation.Play("play");
gobool = true;
startbool = false;
break;
But works together.
How can i escape from this issue?
Thanks in Advance
it's this simple
while ( myAnime.IsPlaying("whichAnime") ) yield;
Answer by EtherIT · Feb 27, 2013 at 11:57 AM
animation.Play("play");
StartCoroutine(WaitAndCallback(animation["play"].length));
in update function
IEnumerator WaitAndCallback(float waitTime){
yield return new WaitForSeconds(waitTime);
gobool = true;
}
@sona.viswam Answer is Good but having two accounts is Bad thing
i was not talking about the methods..... Read last comment again.... i just said having two accounts and posting and accepting the answer between them is not a Good Practise.....Here $$anonymous$$arma Doesn't provide anything Special So please Don't do this kind of the things and Don't create Dummy Accounts....Regards $$anonymous$$aulik
@$$anonymous$$aulik2208: One is $$anonymous$$e. Another is company account using by head in abroad. i saw your rude answer to fafase also. He is trying to help me with good solutions. Please dont hesitate others. You are here to help others or for fight ?
Answer by fafase · Feb 27, 2013 at 10:59 AM
if(animation.isPlaying)
or
if(animation.IsPlaying("myHappyAnimation"))
first check if any animation is playing the second is a function that checks if the animation passed as parameter is playing
Answer by Maulik2208 · Feb 27, 2013 at 11:00 AM
Try yield WaitForSeconds() and in that use the time which is taken by the length of your animation's play.....
Assu$$anonymous$$g that after the play you have to wait for the animation to be finished first and then you want to go to the next line of gobool.....
That is a cumbersome way that would require some booleans to prevent the coroutine to be called many times:
if(noCalled){
StartCoroutine(Wait(animation["play"].length));
noCalled = false;
}
IEnumerator Wait (float f) {
yield return new WaitForSeconds(f);
noCalled = true;
}
or you do
if(animation.isPlaying)
and that is it.
$$anonymous$$aulik your example will start a new coroutine every frame.
i know that that's why i have $$anonymous$$entioned to use Appropriate Restriction Before the Coroutine gets Starts..... Any ways might you haven't seen in my Comment i do appreciate your way to do the thing Sir Thanks for your valuable view on my Answer as well as Comment
Follow this Question
Related Questions
Change boolean after Animation is done 1 Answer
Animation doesn't go back to idle in unity 1 Answer
Set boolean to false when animation changes? 1 Answer
Animation not being played! 0 Answers
Multiple Cars not working 1 Answer