function StopCoroutine (methodName : string) : void
Description描述
Stops all coroutines named methodName running on this behaviour.
停止这个动作中名为methodName的所有协同程序。
Please note that only StartCoroutine using a string method name can be stopped using StopCoroutine.
请注意只有StartCoroutine使用一个字符串方法名时才能用StopCoroutine停用之.
using UnityEngine;
using System.Collections;
public class example : 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;
}
}
}
// 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;
}
}