Version: 5.5
public void StopCoroutine (string methodName);
public void StopCoroutine (IEnumerator routine);

Parameters

methodName Запуск корутины.
routine Name of the function in code.

Description

Останавливает все корутины с именем methodName запущенные на этом MonoBehaviour.

StopCoroutine takes one of two arguments which specify which coroutine is stopped:

- A string function naming the active coroutine
- The IEnumerator variable used earlier to create the coroutine.

Note: Do not mix the two arguments. If a string is used as the argument in StartCoroutine, use the string in StopCoroutine. Similarly, use the IEnumerator in both StartCoroutine and StopCoroutine.

In the JScript example that follows, the string example is provided. In the CS example, the IEnumerator type is used.

using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour { // keep a copy of the executing script private IEnumerator coroutine;

// Use this for initialization void Start() { print("Starting " + Time.time); coroutine = WaitAndPrint(3.0f); StartCoroutine(coroutine); print("Done " + Time.time); }

// print to the console every 3 seconds. // yield is causing WaitAndPrint to pause every 3 seconds public IEnumerator WaitAndPrint(float waitTime) { while (true) { yield return new WaitForSeconds(waitTime); print("WaitAndPrint " + Time.time); } }

void Update() { if (Input.GetKeyDown("space")) { StopCoroutine(coroutine); print("Stopped " + Time.time); } } }