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 Autonomous · Jul 12, 2013 at 04:03 AM · animationcoroutinewaitforseconds

How to implement a "wait" after an animation has finished?

I am trying to add some public functionality to my animation script so that it can be adjusted from the inspector. The intended functionality that I am looking for is when "AddSequenceDelay" is checked (bool=true) that I can then check for the last frame of the animation and set a "Delay Duration".

The problem I seem to be experiencing is that the the WaitForSeconds is not being processed even though I have determined through Debug.log usage that the function is being accessed.

 IEnumerator PlayLoop(float delay)
 {
    //Wait for the time defined at the delay parameter  
    yield return new WaitForSeconds(delay);
             
    //Advance one frame 
    frameCounter = (++frameCounter)%textures.Length;
 
    //Stop
    StopCoroutine ("PlayLoop");
 
    if (AddSequenceDelay == true && frameCounter <= 0)
    {
       Debug.Log ("TEST");
       StartCoroutine("SequenceDelay");
    }
 
    //Stop this coroutine  
    StopCoroutine ("PlayLoop");
 
     
 IEnumerator SequenceDelay()
 {
    yield return new WaitForSeconds(DelayDuration);        
 
    StopCoroutine ("SequenceDelay");
 }


I appreciate any help that can be provided on this debacle. :)

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
Best Answer

Answer by Autonomous · Jul 13, 2013 at 05:14 AM

It turns out that my ordering was just a bit off. To resolve the problem I just reordered the wait code to be checked prior to the playing the loop. Only issue is it waits for the full delay to be processed before the animation plays for the first time. (Example: Delay of 5 seconds will cause the animation to be held up for 5 seconds before it plays for the first time)

IEnumerator PlayLoop(float delay) {

 if (AddSequenceDelay == true && frameCounter <= 0)
     {
         yield return new WaitForSeconds(DelayDuration);
     }
         
     //Wait for the time defined at the delay parameter  
     yield return new WaitForSeconds(delay);
         
     //Advance one frame 
     frameCounter = (++frameCounter)%textures.Length;

     //Stop this coroutine  
     StopCoroutine ("PlayLoop");

}

  • I resolved the issue with the animation being delayed on the first cylce by adding a simple bool check before the sequence delay if statement.

if (firstCycle == true) {

     // Now that the first cycle has taken place, this code will no longer need to be ran
     firstCycle = false;
             
     //Wait for the time defined at the delay parameter  
     yield return new WaitForSeconds(delay);
                 
     //Advance one frame 
     frameCounter = (++frameCounter)%textures.Length;                
 }
Comment
Add comment · 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
0

Answer by JohnnySunshine · Jul 12, 2013 at 10:04 AM

Try

 yield return StartCoroutine("SequenceDelay");

Also, you don't have to call StopCoroutine at the end of a function, it will stop when it reaches the end.

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 Autonomous · Jul 12, 2013 at 11:13 PM 0
Share

Johnny there was no change. The problem isn't that the coroutine isn't being called, it's that the WaitForSeconds is not being applied when the coroutine is run.

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

16 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 avatar image avatar image avatar image

Related Questions

WaitForSeconds bug,Coroutine Bug 1 Answer

(Rapid fire) How to accurately wait for a very short amount of time? 4 Answers

function behaves unexpectedly inside a coroutine. 2 Answers

Gun script help 1 Answer

Having trouble figuring out coroutines in C# 2 Answers


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