Legacy Documentation: Version 4.6(go to latest)
Language: English
  • C#
  • JS
  • Boo

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

MonoBehaviour.StopCoroutine

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public function StopCoroutine(methodName: string): void;
public void StopCoroutine(string methodName);
public def StopCoroutine(methodName as string) as void
public function StopCoroutine(routine: IEnumerator): void;
public void StopCoroutine(IEnumerator routine);
public def StopCoroutine(routine as IEnumerator) as void

Description

Stops all coroutines named methodName running on this behaviour.

Please note that only StartCoroutine using a string method name can be stopped using StopCoroutine.

	// In this example we show how to invoke a coroutine using a string name and stop it

function Start () { StartCoroutine("DoSomething", 2.0); yield WaitForSeconds(1); StopCoroutine("DoSomething"); }

function DoSomething (someParameter : float) { while (true) { print("DoSomething Loop"); // Yield execution of this coroutine and return to the main loop until next frame yield; } }
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    IEnumerator Start() {
        StartCoroutine("DoSomething", 2.0F);
        yield return new WaitForSeconds(1);
        StopCoroutine("DoSomething");
    }
    IEnumerator DoSomething(float someParameter) {
        while (true) {
            print("DoSomething Loop");
            yield return null;
        }
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def Start() as IEnumerator:
		StartCoroutine('DoSomething', 2.0F)
		yield WaitForSeconds(1)
		StopCoroutine('DoSomething')

	def DoSomething(someParameter as float) as IEnumerator:
		while true:
			print('DoSomething Loop')
			yield