Question about Coroutines and waiting for a function to finish

  1. IEnumerator f() {
  2. Debug.Log("f() started");
  3. yield return StartCoroutine(g());
  4. Debug.Log("f() is done");
  5. }
  6. IEnumerator g() {
  7. Debug.Log("g() started");
  8. while (something)
  9. yield return null;
  10. Debug.Log("g() is done");
  11. }
  12. // Somewhere else you start f() like this:
  13. StartCoroutine(f());


this will print:

  1. "f() started"
  2. "g() started"
  3. "g() is done"
  4. "f() is done"

Comentarios

Entradas más populares de este blog

INSTALL ANDROID-29 UNITY

Admob Unity II

Flutter en iOS: themeMode no cambia a modo oscuro si se usa `ThemeMode.system`