Starting Coroutine within Start method

Hi All,

I use C# for scripting in Unity.

Say I have a coroutine method…let name ia f so it goes somthing like this:

private IEnumerator f()
{
   while (true)
   {
     do things
    }
}

Rather calling the f every frame the coroutine uses while(true) loop.

The Start method look like thaht:

void Start
{
startCoroutine(f());

}

When I press play button Unity freezes and does not responds. I check Unity’s doc and it looks like it should work. I don’t understands the problem.
please help me

Thank u in advance

Unity doesn’t freeze, it is just executing your while loop. It will keep doing this until the condition is no longer true, or you yield.

private IEnumerator f()
{
   while (true)
   {
     //do things
     yield return null; //after having done things, exit this loop and wait null frames before reentering. So the next frame 'things' will happen again.  
   }
}