I have a while loop in function Start(), in a script attached to an empty game object, so that I can instantiate waves of enemies during a certain time. It works if I do this:

//gameTime descends from 400.0
function Start () 
{
	while(gameTime > 280.0);
	{
		Instantiate(enemy, Vector3(-9,12.46,0), enemy.transform.rotation);
		yield WaitForSeconds(1.0);
		Instantiate(enemy, Vector3(-9,12.46,0), enemy.transform.rotation);
		yield WaitForSeconds(1.0);
		Instantiate(enemy, Vector3(-9,12.46,0), enemy.transform.rotation);
		yield WaitForSeconds(10);
	}

But if I change the while condition to:

    while(gameTime > 280.0 && gameTime < 340 );

it doesn’t work. Any ideas why that might be?

In your example, you have a semicolon immediately following a while statement. With that there, your loop isn’t ever even going to run (and should generate an error).

The while statement with two conditions looks fine (except for one being a float and one being an int, but I’m not sure how picky javascript is on that, so you may be okay in that regard). Just ditch the semicolon and you should be alright.

Also as a rule, put brackets around each condition

while(  (gameTime>280.0)  &&  (gameTime < 340.0)  )

So I tried Razion’s suggestion of separating the conditions with brackets, but still no luck unfortunately. Unity does not return any error when I run the code, it just simply doesn’t instantiate my prefabs. Here is the code I tried that didn’t work:

function Start () 
{
	InvokeRepeating("CountDown",1.0,1.0);


	while((gameTime > 280.0) && (gameTime < 390.0))
	{
			Instantiate(enemy, Vector3(-9,12.46,0), enemy.transform.rotation);
			yield WaitForSeconds(1.0);
			Instantiate(enemy, Vector3(-9,12.46,0), enemy.transform.rotation);
			yield WaitForSeconds(1.0);
			Instantiate(enemy, Vector3(-9,12.46,0), enemy.transform.rotation);
			yield WaitForSeconds(10);
	}
}

As I said before, with just one condition (gameTime > 280.0) it works fine, just not with the other condition. I’m stumped. Any other suggestions for a better system to instantiate my enemies are also welcome.