Calling a co-routine inside a co-routine

Hi,

according to lecture “Nested co-routines” in the RPG Core tutorial, when calling a co-routine in another co-routine (nested co-routines) we don’t need to use “StartCoroutine()”, isn’t it?

Thanks in advance and best

When calling from inside a Coroutine, you want to use the yield return keywords…

IEnumerator A()
{
    Debug.Log("This should show 20 seconds before...");
    yield return B();
    Debug.Log("This statement.");
}

IEnumerator B();
{
     yield return new WaitForSeconds(20);
}

void Start()
{
    StartCoroutine(A());
}

Thanks for the kind reply.

So, we can summarize saying that

  1. For calling a co-routine, we need StartCoroutine()
  2. For calling a co-routine in another co-routine, we simply need yield return.

Correct?

Thanks and best!

Jader

That’s correct.

Privacy & Terms