What is IEnumerators ?
IEnumerators are used to allow a program to yield things like the WaitForSeconds function, which tells the script to wait without hogging the CPU.
StartCoRoutine essentially runs a function in another thread when used with yield. The execution of a coroutine can be paused at any point using the yield statement. The yield returns a value specifies when the coroutine is resumed.
Example : In this example CPU will wait for 5 seconds and after that "This is the use of IEnumerator..." will be printed.
public void function()
{
StartCoroutine (timing());
}
IEnumerator timing()
{
yield return new WaitForSeconds (5.0f);
Debug.Log("This is the use of IEnumerator...");
}
0 Comment(s)