Skip to main content
1 of 4
vito
  • 107
  • 9

Instantiate objects in a List and use it

Why does the following code not work?

I want to instantiate prefabs in a list and then use it as a GameObject like that :

public GameObject prefab;

void Start()
{

 ArrayList players = new ArrayList();

  for(int i=0; i<5; i++)
  {
        numbers.Add( (GameObject)Instantiate(prefab));
  }

  players[2].transform.position = new Vector3(1, 1, 1);

}
vito
  • 107
  • 9