Game Development Reference
In-Depth Information
Using StartCoroutine with method name (string)
In most cases, you want to use the StartCoroutine variation at the start of a code.
However, StartCoroutine using a string method name allows you to use
StopCoroutine with a specific method name.
Tip
The downside is that the string version has a higher runtime overhead to start
coroutine , and you can pass only one parameter.
In the following example, we will see how to invoke coroutine using a string name and
stop it:
// JavaScript user:
function Start() {
// Start Coroutine DoSomething
StartCoroutine("DoSomething", 5.0);
// Wait for 2 seconds
yield WaitForSeconds(2.0);
// Stop Coroutine DoSomething
StopCoroutine("DoSomething");
}
function DoSomething (someParameter : float) {
while (true) {
// DoSomething Loop
Debug.Log ("DoSomething Loop = " + Time.time);
// Yield execution of this coroutine and return to the
main loop until next frame
yield;
}
}
// C# user:
Search WWH ::




Custom Search