Legacy Documentation: Version 5.1
LanguageEnglish
  • C#
  • JS

Script language

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

MonoBehaviour.StopCoroutine

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

Parameters

methodName Name of coroutine.
routine Name of the function in code.

Description

Stops the first coroutine named methodName, or the coroutine stored in routine running on this behaviour.

	// 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; } }