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
1
Question by sudhir_kotila · Aug 08, 2014 at 02:16 PM · javascript

How to stop co-routine?

When two co-routine is running.Then how to stop first co-routine? GLOBALS.stableTime = 5;

 IEnumerator StableWaittingTime ()
 {
         yield return new WaitForSeconds (1f);
         if (GLOBALS.stableTime == 0) {
                 GameManager.instance.LevelFaildMethod ();
         } else {
                 GameManager.instance.stableWaittingTime.text = GLOBALS.stableTime.ToString ();
                 GLOBALS.stableTime--;
                 StartCoroutine ("StableWaittingTime");
         }

}

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 gjf · Aug 08, 2014 at 02:24 PM 0
Share

http://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.StopCoroutine.html

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Kiwasi · Aug 08, 2014 at 08:09 PM

Two methods come to mind

The best method I can suggest is using the string form of StartCoroutine. Then you can call StopCoroutine directly.

 StartCoroutine("StableWaittingTime");
 StopCoroutine("StableWaittingTime");

The other method is build you coroutine so is automatically aborts when the condition is satisfied.

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 sudhir_kotila · Aug 09, 2014 at 11:51 AM 0
Share

Thank you Bored$$anonymous$$ormon, but i have one doubt if i write startcoroutine first and i write StopCoroutine second then strarted Coroutine will be stppoed.

$$anonymous$$y issue is i want to stop older one coroutine then i want to start new coroutine cos i handle only one variable in both coroutine so that in this case problem is that when i start second coroutine at that time the var's value is increased speedy (means twise) because that my older one coroutine is already start and the variable is same.

What can i do for prevent this?

avatar image Kiwasi · Aug 09, 2014 at 08:26 PM 0
Share

I can't believe I'm writing this, but the following code will stop the old coroutine before starting the new one.

 StopCoroutine("StableWaittingTime");
 StartCoroutine("StableWaittingTime");
avatar image sudhir_kotila · Aug 11, 2014 at 05:53 AM 0
Share

How can you know that your co-routine is stopped and can you send me your tested code because that in my script that not worked cos as i m say i have two button for to start the co-routine.you used to buttons for start that co-routines.

avatar image Kiwasi · Aug 11, 2014 at 06:00 AM 0
Share

The docs are clear enough on how to do this, I've given you the pointers you need to figure it out. Can't help much more. I'm out on this one.

Try stamp collecting ins$$anonymous$$d?

avatar image sudhir_kotila · Aug 14, 2014 at 09:27 AM 0
Share

Hey, Bored$$anonymous$$ormon its work thanking to you.

avatar image
2

Answer by Andres Barrera · Aug 08, 2014 at 07:40 PM

Take a look at this: https://gist.github.com/onevcat/5261702

It's not my work, but I have tested it and is really helpful.

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
1

Answer by Hardik · Nov 18, 2014 at 07:55 AM

You can also use yield break for stop co-routine

 IEnumerator DoCheck() {
     yield return new WaitForSeconds (1f);
     //Do your stuff here
     yield break;
 }

 
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

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

How to handle 5 touches at a time? 2 Answers

Move Object by dragging (mobile) makes the balls fall from the cup 1 Answer

PhotonNetworking Colliders of players dont collide 0 Answers

Realtime Multiplayer Plugin 2 Answers

Instantiate prefab randomly but not in already genrated position 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