• 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 Oct 10, 2013 at 02:04 AM by clunk47 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Zhinkk · Oct 09, 2013 at 11:14 PM · coroutineyield waitforsecondsnotworking

Coroutine yield return new Waitforseconds not working

Here's my code:

         if(CubeScript.startSpeed <= 25){    
             StartCoroutine("IncSpeed");    
             
         }



And my coroutine:

 IEnumerator IncSpeed(){
     Debug.Log("before");
     yield return new WaitForSeconds(5);
     Debug.Log("after");
     
 }


It debugs "Before" in the console, but not "after". Am I not using this coroutine correctly?

Comment
Add comment · Show 7
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 TrickyHandz · Oct 10, 2013 at 12:57 AM 1
Share

You are calling it correctly. By chance have you tried lowering the wait to 1? Sometimes 5 seconds can seem like and eternity when you're testing.

avatar image Zhinkk · Oct 10, 2013 at 01:24 AM 0
Share

Yeah, I've tried 1 second. Still doesn't work. Any ideas?

avatar image TrickyHandz · Oct 10, 2013 at 01:27 AM 5
Share

There are several things that could cause a coroutine to stop. The most common thing that I have seen is the object being destroyed during a coroutine through some other event. Subsequently, the coroutine will be destroyed with the object that was running the coroutine.

avatar image robertbu · Oct 10, 2013 at 01:33 AM 4
Share

Disabling the game object the script is attached to or setting Time.timeScale = 0 will also stop coroutines.

avatar image TrickyHandz · Oct 10, 2013 at 01:47 AM 2
Share

@Zhinkk, feel free to post the solution you found as an answer and mark it as accepted. It is perfectly fine to post and answer to your own question when you discover what the problem was. That way other people with this problem can see what you did to solve it when they run a search.

Show more comments

1 Reply

  • Sort: 
avatar image
6
Best Answer

Answer by Zhinkk · Oct 10, 2013 at 01:42 AM

I failed to realize the script was being destroyed in the process. Thanks, though! I appreciate the help. :)

Comment
Add comment · Show 3 · 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 insaineyesay · Dec 24, 2013 at 03:50 PM 0
Share

This helped me out too! Thanks!

avatar image ajdrew81 · Aug 21, 2015 at 01:27 AM 0
Share

It's a simple thing to overlook, yet takes awhile to find the fix. Thanks!

avatar image yami7 · Jun 02, 2016 at 08:55 PM 0
Share

excatly where?

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

Related Questions

Coroutine "While" Setup 1 Answer

Reset WaitForSeconds Coroutine 1 Answer

Yield Never Works 4 Answers

Please help with While Loops 1 Answer

How to end a coroutine early 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges