Trouble with Enemy spawn (Javascript)

I’m having a problem with my enemy spawning. It’s basic spawning, 10 Enemies will spawn from a point 1 second apart from each other. My problem is that they all spawn at the same time, and because they have rigidbody’s, they push each other off of the edge of my platform (I’m doing a sidescroller and they fall off either behind the platform, or infront of it). How do I stop them spawning all at once, and also keeping them on? Here’s the spawning code:

var Enemy: Transform;
var SpawnEnemies: int = 0;
var spawn = false;

function Update () {
	if(SpawnEnemies <= 8 && (spawn))
	{
		InvokeRepeating ("Spawn",1,1);
	}
	else if(SpawnEnemies > 10)
	{
		CancelInvoke("Spawn");
		spawn = false;
	}
}

function OnTriggerEnter(other: Collider){
	if(other.tag == "Player")
	{
		spawn = true;
	}
}

function Spawn(){
	var instantiatedenemy = Instantiate(Enemy,GameObject.Find("EnemySpawn").transform.position, transform.rotation); 
	SpawnEnemies +=1;
}

Also, for them falling off, that problem shouldn’t be happening cause in the EnemyScript, I say that the transform.position.z of each enemy is -19 which is the center of my game world. If you need code for this question, because it is a secondary question I’m not to concerned with it at the moment, just ask, and I’ll post the required code.

Thank you for any help from you guys.

Tim Radder

You should not start InvokeRepeating every Update! It should be called only once to start spawning the enemies, and stopped when they reached the desired number:

var Enemy: Transform;
var SpawnEnemies: int = 0;
var spawn = false;

function OnTriggerEnter(other: Collider){
    if (other.tag == "Player" && spawn == false){
       InvokeRepeating ("Spawn",1,1); // start Invoke
       spawn = true; // make sure Invoke started only once
    }
}

function Spawn(){
    var instantiatedenemy = Instantiate(Enemy,GameObject.Find("EnemySpawn").transform.position, transform.rotation); 
    SpawnEnemies +=1;
    if (SpawnEnemies >= 10){ // stop Invoke here
        CancelInvoke("Spawn");
        spawn = false;
    }
}