Unity crashes when running the following code

I’m trying to spawn a number of object flying over the screen from left to right. I’m using the follow code:

public Vector2 o;
public float timeLeft = 1f;
public GameObject irri;

void FixedUpdate () 
					{
		o = irri.rigidbody2D.velocity;
		o.x = -2;
		irri.rigidbody2D.velocity = o;
}

IEnumerator Spawn2()
	{
		while (timeLeft > 0)
		{		
				if (syanMode == 1)
			{
				Vector3 spawnPosition2 = new Vector3 (2.0f, Random.Range (0, 0.5f), 0.0f);	
				Instantiate (irri, spawnPosition2, Quaternion.Euler(0.0f, 0.0f, Random.Range(0.0f, 360.0f)));
				yield return new WaitForSeconds ( Random.Range (0.1f, 0.5f));
			}
		}


	}

I have created an asset that has a rigidbody2d and a sprite, and assigned that to the variable irri in the scene.

as soon as I hit play to test if it works, unity freezes. why is that?

You need to yield if the ‘if’ isn’t executed

I don’t see where you’re changing timeLeft to be less then 0, you might try timeLeft >= 0.

So the while loop is stuck in the loop