I want to run my code multiple times without using the Update() method, now, I could use a coroutine or an Invoke(), but since the Invoke() is not very performance friendly as a coroutine, my best option is to use a coroutine instead.
Now, my problem is, when my coroutine is completed and I want to restart it, how exactly should I do it?
Here is what I've done, but it doesn't work:
private void Start()
{
StartCoroutine(DoSomething());
}
private IEnumerator DoSomething()
{
//Does something
yield return new WaitForSeconds(20f);
//Does another thing
yield return new WaitForSeconds(20f);
StartCoroutine(DoSomething());
}
yield return new WaitForSeconds(20f);
is the correct way to do a 20 second pause in a coroutine method. For more information about what happens here syntactically, check out the article about the yield keyword in the C# language. \$\endgroup\$