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 fantom642 · Jan 10, 2015 at 02:39 PM · coroutinecoroutineshowhow-to

How to stop a coroutine with multiple parameters?

I know about StopAllCoroutines() that stops all coroutines and yield break that stops it from within the coroutine; But Is there a way how to stop one Coroutine with multiple parameters from outside?

Thanks

Comment
Add comment · Show 2
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 vexe · Jan 10, 2015 at 02:52 PM 0
Share

StopCoroutine takes a IEnumerator parameter since 4.5 so you should be able to pass in any coroutine with arbitrary number of arguments, have you tried that?

avatar image fantom642 · Jan 10, 2015 at 03:12 PM 0
Share

Thanks, I realised that I still have 4.3, I'll update it and try it out

1 Reply

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

Answer by hypnoticmeteor · Jan 10, 2015 at 03:09 PM

 using UnityEngine;
 using System.Collections;
 
 public class testCo : MonoBehaviour {
 
     
     IEnumerator play(int one, int two, int three)
     {
 
         print(one);
         print(two);
         print(three);
         yield return null;
     }
     void Update () {
 
         int t = (int)Time.time;
         if (t < 10)
         {
             StartCoroutine(play(1, 2, 3));
         }
         else {
             StopCoroutine("play");
             print("stopped");
         
         }
 
     }
 }

I do not know about the guy who was told me I was wrong. To stop a coroutine just

 StopCoroutine("functionName").

To call it from outside this script put the line in a public function and call it.

Comment
Add comment · Show 2 · 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 fantom642 · Jan 10, 2015 at 03:39 PM 0
Share

Do you have any idea, why this doesn't work?

 using UnityEngine;
 using System.Collections;
 public class test : $$anonymous$$onoBehaviour
 {
         IEnumerator play (int one, int two, int three)
         {
                 while (true) {
                         print (one);
                         print (two);
                         print (three);
                         yield return null;
                 }
         }
 
         public void On$$anonymous$$ouseUp ()
         {
                 print ("stopped");
                 StopCoroutine ("play");
                 return;
         }
     
         public void On$$anonymous$$ouseDown ()
         {
                 print ("started");
                 StartCoroutine (play (1, 2, 3));
                 return;
         }
 }

(it's attached to a gameObject ofc)

avatar image hypnoticmeteor · Jan 10, 2015 at 03:51 PM 0
Share
 using UnityEngine;
 using System.Collections;
 
 public class testCo : $$anonymous$$onoBehaviour {
 
     bool set;
 
     IEnumerator play(int one, int two, int three)
     {
 
         print(one);
         print(two);
         print(three);
         yield return null;
     }
     void Update () {
         if (set)
         {
             StartCoroutine(play(1, 2, 3));
         }
         else {
             StopCoroutine("play");
             print("stopped");
         
         }
 
     }
 
     public void On$$anonymous$$ouseUp()
     {
         set = false;
     }
     public void On$$anonymous$$ouseDown()
     {
         set = true;
     }
 }
 
 

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

NullReferenceException in StartCoroutine 1 Answer

Flash image while ammo is low - coroutines? 3 Answers

Coroutines not passing yield 1 Answer

Collection Change During Iteration 0 Answers

Why doesnt my coroutine ever end? 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