I try this:
void RUN()
{
Debug.Log("Before Corutine");
StartCoroutine(Test());
Debug.Log("After Corutine");
}
IEnumerator Test()
{
Debug.Log("Before Wait");
yield return new WaitForSeconds(5);
Debug.Log("After Wait");
}
And I get:
Before Corutine
Before Wait
After Corutine
(after 5 seconds)
After Wait
My dream is get:
Before Corutine
Before Wait
(wait 5 seconds)
After Wait
After Corutine
Is it possible?
You'll need to make RUN
a coroutine (adjusting all calls to it accordingly), and you'll need to yield
the result of StartCoroutine
.
EDIT :
IEnumerator RUN()
{
Debug.Log("Before Corutine");
yield return StartCoroutine(Test());
Debug.Log("After Corutine");
}
IEnumerator Test()
{
Debug.Log("Before Wait");
yield return new WaitForSeconds(5);
Debug.Log("After Wait");
}
Wherever you call RUN()
, you must now call with StartCoroutine(RUN());
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.