New Coder Needs Helps with IEnumerator

Hi,

You could edit your post to use code tags, then it would be so much easier on the eyes…

You could also make your Coroutine more flexible by passing the item that is to be run as a parameter.
This way you could use the same code for different things you need to delay.
i.e.

void Start()
{
    StartCoroutine(WaitforMoment(AfterWait));
}

IEnumerator WaitforMoment(Action afterWait)
{
    Debug.Log("Start waiting");
    yield return new WaitForSeconds(5);
    afterWait();
}

void AfterWait()
{
    Debug.Log("Wait is over");
}
1 Like