Sunday, January 21, 2018

unity - 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++)
{
players.Add( (GameObject)Instantiate(prefab));
}

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


}

there is an error message


enter image description here




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...