Unity3d Tutorial: How to use C # script yield

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.