Problem while looping through prefabs
Hi, I am writing a spawning system, and I try to code it to be able to set some "SpawnNodes" at specific position on the scene, which are stored in an Array.
Then for each wave of enemy ( which are prefabs stored in an Array), I loop through the array, and spawn the prefab to the location of the SpawnNode, based on their index (see below)
private void SpawnEnemies()
-
{
foreach (EnemySpawn enemySpawn in enemySpawnArray)
{
int index = Array.IndexOf(enemySpawnArray, enemySpawn);
enemySpawn.Spawn(battleSystem.spawnNode[index].transform);
}
}
In the EnemySpawn script :
public void Spawn(Transform spawningPoint)
{
Instantiate(gameObject, spawningPoint);
}
The big problem I encounter here, is when I put 2 copies of the same prefab enemy in the array, the foreach loop processes all of these as the same prefab, and spawns all of them on the same SpawnNode.
De you know a way to tell this loop to process each prefab as its own object ?
Thanks
Your answer
Follow this Question
Related Questions
Remove an object from a list and add another other obejct? 0 Answers
For some reason I cannot drag my prefabs from the Project folder into the scene hierarchy. 2 Answers
Limit an amount of prefabs instantiated in javascript for Unity 5. 0 Answers
my instantiation /prefab of dan wont play death animations like orignal dan 0 Answers