| methodName | コルーチン名 | 
| routine | コード内の関数名 | 
この Behaviour 上で実行されている methodName という名のコルーチン、または routine として保持されているコルーチンをすべて停止します
StopCoroutine は停止するコルーチンを指定する 2 つの引数のうちの 1 つを使います。
- A string function naming the active coroutine
- 以前にコルーチンを作成するために使った IEnumerator 変数
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.
以下の JavaScript の例では、文字列の例が表示されています。C# の例では、IEnumerator 型が使われています。
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); } } }