Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Mar 04, 2013 at 04:13 AM by sona.viswam for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by sona.viswam · Feb 27, 2013 at 10:52 AM · c#animationbooleanwait

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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Feb 27, 2013 at 11:33 AM 1
Share

it's this simple

  while ( myAnime.IsPlaying("whichAnime") ) yield;

3 Replies

  • Sort: 
avatar image
1
Best Answer

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;      
 }
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Maulik2208 · Feb 27, 2013 at 12:25 PM 1
Share

@sona.viswam Answer is Good but having two accounts is Bad thing

avatar image sona.viswam · Feb 27, 2013 at 12:41 PM 0
Share

what you mean. which is the best method?

avatar image Maulik2208 · Feb 27, 2013 at 01:15 PM 0
Share

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

avatar image sona.viswam · Feb 28, 2013 at 03:38 AM 2
Share

@$$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 ?

avatar image
2

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sona.viswam · Feb 27, 2013 at 12:45 PM 0
Share

it not suits for my requirement

avatar image
0

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.....

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Maulik2208 · Feb 27, 2013 at 11:01 AM 0
Share

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.....

avatar image sona.viswam · Feb 27, 2013 at 11:03 AM 0
Share

it wont works in update function

avatar image fafase · Feb 27, 2013 at 11:23 AM 1
Share

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.

avatar image fafase · Feb 27, 2013 at 11:25 AM 1
Share

$$anonymous$$aulik your example will start a new coroutine every frame.

avatar image Maulik2208 · Feb 27, 2013 at 11:31 AM 0
Share

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

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges