Stop单个Coroutine
public Coroutine StartCoroutine(string methodName, object value = null);
Description
Starts a coroutine named methodName
.
In most cases you want to use the StartCoroutine variation above. However StartCoroutine using a string method name allows you to use StopCoroutine with a specific method name. The downside is that the string version has a higher runtime overhead to start the coroutine and you can pass only one parameter.
// 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; } } }