Only 1 of the multiple instantiated clones of an object is getting added to my list, instead of ALL of them. Also, is it possible to store all such clones under a single variable so I can access all of them from a different script ??
Here is my code:
public GameObject[] enemies; // Array of enemy prefabs.
List<GameObject> instantiatedCrowd;
public GameObject instantiatedEnemies;
void Start ()
{
// Start calling the Spawn function repeatedly after a delay .
InvokeRepeating("Spawn", spawnDelay, spawnTime);
}
void Spawn ()
{
// Instantiate a random enemy.
int enemyIndex = Random.Range(0, enemies.Length);
instantiatedEnemies = Instantiate(enemies[enemyIndex], transform.position, transform.rotation) as GameObject;
instantiatedCrowd.Add (instantiatedEnemies.gameObject);
}