Skip to main content
edited tags
Link
Vaillancourt
  • 16.4k
  • 17
  • 55
  • 61
added 120 characters in body
Source Link
vito
  • 107
  • 9

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

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);

}

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

deleted 2 characters in body
Source Link
vito
  • 107
  • 9

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

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

}

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);

}

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);

}
Source Link
vito
  • 107
  • 9
Loading