Run Coroutine again if condition not met

Can someone explain the best way to achieve this…

private void OnTriggerEnter(Collider other) {
    StartCoroutine(ShowMyGameobject());
}

IEnumerator ShowMyGameobject() {
        gameObject.transform.position = new Vector3(0,0,0);
        yield return new WaitForSeconds(180.0f);
        if(canIShowIt) {
              gameObject.transform.position = initialPosition;
        } else {
              //Run coroutine again
        }
}

Basically I move my gameobject out of the way and after 3 minutes I return it, but, if something is happening that prevents it from returning I just want to run it again and try again in 3 minutes.
Do i use an infinite while loop? I don’t want to use too many resiources given it’s a mobile game.

THanks

While loop is fine. Don’t worry to much about performance unless you see performance issues.

while(!canIShowIt)
{
  yield return new WaitForSeconds(180);
}
1 Like

oh wow that’s simple and awesome. I feel dumb. Thanks