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