I have some working spawn scripts but got an idea to modify a Random Spawner script from a tutorial which would benefit my game. Basically, I want to remove the randomness from this. I assumed initially that If I put the same amount of enemy prefabs as spawn points there’d be no randomness and each spawn point would initialize an enemy prefab but that didn’t happen.
What I’m looking for is when the trigger is activated my 5 prefabs are instantiated on those 5 spawn points.
public Transform[] spawnPoints;
public GameObject[] enemyPrefabs;
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Enemy_Trigger"))
{
Spawn();
}
}
private void Spawn()
{
int randEnemy = Random.Range(0, enemyPrefabs.Length);
int randSpawnPoint = Random.Range(0, spawnPoints.Length);
Pooler.Spawn(enemyPrefabs[0], spawnPoints[randSpawnPoint].position, transform.rotation);
}
I tried removing the two int lines and gave the value of 0 to spawnPoints instead of randSpawnPoint but that just acted like a single spawner. How can I get each item in both arrays to instantiate when triggerred?