Game Development Reference
In-Depth Information
Closing the gap
So now that we understand how we call Coroutines, to make the Print10Lines meth-
od described earlier, we will call it as follows:
void Example1()
{
StartCoroutine(Print10Lines());
print("I started printing lines");
}
As explained, the preceding code will kick off the Print10Lines function and then
continue forward while the routing to print the lines continues simultaneously. On the oth-
er hand, the following code will print 10 lines, and only after it is finished will it continue
and notify you that printing has finished:
IEnumerator Example2()
{
yield return StartCoroutine(Print10Lines());
print("I have finished printing lines");
}
Tip
Any method that has a return type of IEnumerator has to be called using one of the
StartCoroutine methods; just calling any method with IEnumerator on its own
will do nothing. So, keep this in mind if you are wondering why something is not being
called.
Search WWH ::




Custom Search