Instantiate 1 at a time at each transform in array

Hello there, I’m making an enemy spawner and since arrays are fairly new to me I’m stuck at one point. I want it to spawn 1 enemy at each transform in the array. And so far it just spawns everything at first transform in the array. What am I doing wrong?

Here’s the code:

var spawnPoint : Transform[];
var spawns : GameObject[];
var difficultyMultiplier : float = 1.0;
var spawnTime : float = 5.0;
var spawnsPerSpawnPoint : int = 1;
private var spawnTimer : float = 0.0;

function Update()
{
	spawnTimer += Time.deltaTime;
	if(spawnTimer >= 5.0)
	{
		SpawnTimer();
	}
}

function SpawnTimer()
{
	for (var i = 0; i < spawnsPerSpawnPoint; i++)
	{
		Instantiate(spawns[(Random.Range(0, spawns.Length))], spawnPoint[(Random.Range(0,spawns.Length))].position, Quaternion.identity);
	}
	spawnTimer = 0.0;
}

I’m probably mistaken but the way I understand my instantiate line is that it should spawn a random gameobject in the array at a random transform in the other array. :s

Thanks you!

I’m confused.

  1. Your for loop starts from 0, and the condition is < 1. This means there’s only one iteration…
  2. Your instantiate location is a random transform, instead of methodically instantiating from start to finish of the array.

If you want to spawn per spawnsPerSpawnPoint spawns in each point:

function SpawnTimer()
{
    for (var i = 0; i < spawnPoint.Length; i++)
    {
        for (var j = 0; j < spawnsPerSpawnPoint; j++) {
            Instantiate(spawns[(Random.Range(0, spawns.Length))], spawnPoint*.position, Quaternion.identity);*

}
}
spawnTimer = 0.0;
}