Skip to main content
added 524 characters in body
Source Link
Philipp
  • 123.2k
  • 28
  • 264
  • 345

You can simply put an infinite loop in your coroutine.

private IEnumerator DoSomething()
{
    while(true) {
        //Does something
        yield return new WaitForSeconds(20f);
        //Does another thing
        yield return new WaitForSeconds(20f);
    }
}

You can still stop that loop by destroying the game object which started the coroutine or with StopCoroutine. If you have some exit condition for the loop which you want to check within the coroutine, you can either turn the infinite while-loop into a while-loop with a condition or break out of the loop with the break; keyword.

You can simply put an infinite loop in your coroutine.

private IEnumerator DoSomething()
{
    while(true) {
        //Does something
        yield return new WaitForSeconds(20f);
        //Does another thing
        yield return new WaitForSeconds(20f);
    }
}

You can simply put an infinite loop in your coroutine.

private IEnumerator DoSomething()
{
    while(true) {
        //Does something
        yield return new WaitForSeconds(20f);
        //Does another thing
        yield return new WaitForSeconds(20f);
    }
}

You can still stop that loop by destroying the game object which started the coroutine or with StopCoroutine. If you have some exit condition for the loop which you want to check within the coroutine, you can either turn the infinite while-loop into a while-loop with a condition or break out of the loop with the break; keyword.

Source Link
Philipp
  • 123.2k
  • 28
  • 264
  • 345

You can simply put an infinite loop in your coroutine.

private IEnumerator DoSomething()
{
    while(true) {
        //Does something
        yield return new WaitForSeconds(20f);
        //Does another thing
        yield return new WaitForSeconds(20f);
    }
}