• 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
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

People who like this

0 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
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

People who like this

0 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 : MonoBehaviour
 {
         IEnumerator play (int one, int two, int three)
         {
                 while (true) {
                         print (one);
                         print (two);
                         print (three);
                         yield return null;
                 }
         }
 
         public void OnMouseUp ()
         {
                 print ("stopped");
                 StopCoroutine ("play");
                 return;
         }
     
         public void OnMouseDown ()
         {
                 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 : MonoBehaviour {
 
     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 OnMouseUp()
     {
         set = false;
     }
     public void OnMouseDown()
     {
         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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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 make UI text appear on screen for a limited time then disappear 1 Answer

Updating a Value in OnTriggerEnter and Returning That Value Immediately... 0 Answers

How to disable game elements for a fixed duration then re-enable them automatically, even if game is reopened 1 Answer

Stuck while solving a Coroutine problem 0 Answers

Toggling bools automatically using coroutines 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