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 /
avatar image
0
Question by PasZ · May 03, 2012 at 10:28 PM · updatewaitforsecondsdelaywait

Activate Animation => Wait => Hide Gameobject

Hi there! Im developing with Vuforia AR plugin. I want to Activate an animated gameobject, wait for some seconds and the hide that gameobject and show another one! I tried differents things(invoke, WaitForSeconds, Destroy(GO,time)<= this one runned ok but when I tried to show the GO again obviusly I was in trouble) but I can't make it run the delay. The code:

 public IEnumerator Delay () 
 {
     Debug.Log("Funcion delay");
     yield return new WaitForSeconds(0.1f);
 }
        
 void Update() 
 {
     if( TouchEvent ) // PSEUDO CODE
     {
         // ** RELEVANT PART **
         menu2.renderer.enabled = false;
         GameObject animacion = GameObject.Find("RULETA");
         activarAnimacion(animacion);
         
         desactivarAnimacion(animacion);
         menu2.renderer.enabled = true;
         // ** RELEVANT PART **
     }
 }
 
 void activarAnimacion(GameObject animacion)
 {
     // [...]
     //activo la animacion
     animacion.animation.Play();
     Delay();
 }
 void desactivarAnimacion(GameObject animacion)
 {
     // [...]
     //desactivo la animacion
     animacion.animation.Stop();
     Debug.Log("Desactiva anim");
 }


Thank you!

[ Edit by berenger : trimmed irrelevant code. Full code available at http://pastebin.com/nA3SXHRt]

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Berenger · May 03, 2012 at 10:50 PM

So, you are not using coroutines correctly.

First, a coroutine will only delay the execution of the code following the yield inside its scope. Wich means that your Delay function exectute the Debug.Log, wait and leave. But Update didn't wait. So the animation was started the stopped at the same frame.

Secondly, in C# you need to call a coroutine with StartCoroutine, or it won't be executed at all.

You can't use Invoke directly because you have a parameter. You could store the animacion variable into a member though. Anyway, for the coroutine. When you have the event triggering the animation, use StartCoroutine( Animate(animacion) ); Here is Animate's code :

 private IEnumerator Animate( GameObject A )
 {
     // ...
     activarAnimacion( A );
     
     // Unless you're sure the animation's length is 0.1 seconds,
     // you should use A.animation[ A.animation.clip.name ].Length here
     yield return new WaitForSeconds(0.1f);
 
     // ...
     desactivarAnimacion( A );
 }


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 Kehos · Aug 27, 2012 at 01:09 AM 0
Share

Thanks a lot for this answer, I've been 4 days searching for something like that :)

avatar image
0

Answer by PasZ · May 04, 2012 at 07:36 PM

Hey dear! Lot of thanks for your answer! I tried compiling with this code: http://pastebin.com/NV2aLt5A

But nothing was rendered! So I used debugging logs and I checked that the Animate function never is executed! Any idea??

PasZ

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 Berenger · May 04, 2012 at 08:10 PM 0
Share

Try this one. I changed the start function, the wait length and the inside of the switch

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

EditorGUI Update function problems 1 Answer

How to create a delay in a function being called in update? 2 Answers

Animation delay until certain distance 3 Answers

Better way for a timer to load a level? 1 Answer

Hide GameObject - Re-Apear after 5sec 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