Stuck in a forever loop.

Hi, I have probably quite a silly question but I am confused about something. A little while ago I created a loop where it would generate a ‘random’ number every x seconds while the game was running. To begin with I wanted it to start doing this at the start of the game or in the Start method so I wrote

private void start()
{
while(gameIsRunning){
     StartCoroutine(NumberSpawner());
    }
}

Anyways something like that. It broke the game of course. So I switched the while loop into the coroutine and it works. But here is my question from my understanding Start only gets called once thats why i put it in there to begin with. How can it create this forever loop?

It never get out of start because it doesn’t end.
Think about it:
-call start
-start call infinite loop

  • game wait for start to end
  • start wait for infinite loop to end
    Waiting for godot take less time
2 Likes

Ah cheers, Yes that makes sense. For some reason my logic seemed to be really off haha