Reputation: 21
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?
Upvotes: 0
Views: 181
Reputation: 203834
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());
.
Upvotes: 3