Coroutines & Yield is an important concept in Unity3d programming, which can be implemented to defer execution of a program or to distribute its parts in a single time period, but in JavaScript and C # coroutines & Yield, there are some grammatical differences:
The yield usage in JavaScript is simple, direct yield on the line, or yield waitforseconds (2);
The usage in C # is as follows:
Yield cannot be used alone
Needs to be used in conjunction with return, for example:
1 yield return 0; Wait 0 Frames
2 yield return 1; Wait 1 frames
3 yield return waitforseconds (3.0); Wait 3 seconds
All functions that use yield must set the return value type to the IEnumerator type, for example:
1 IEnumerator dosomethingindelay () {...}
Finally, the key point that is not mentioned in the "Using C #" section is that all IEnumerator type functions must be triggered using the "startcoroutine" function and cannot be used alone, for example:
1 Startcoroutine (Dosomethingindelay ());
Unity3d Tutorial: How to use C # script yield