I am trying to generate some terrain with the following code:
// Spawn initial rocks.
// variable 'rocks' is type List<GameObject>
for (int i = 0; i < rockCount; i++)
{
GameObject rock = Instantiate(Resources.Load("Prefabs/Rock")) as GameObject;
rocks.Add(rock);
// (Code to reposition goes here, it's not the problem)
}
I would think that this generates rockCount number of clones of the rock prefab, but every time I run it it only makes a seemingly random number of them (usually about a quarter rockCount). The for loop is definitely running rockCount times, but the remaining entries in the list rocks fill up with “Missing (Game Object)”. I’ve tried putting this instantiation in a while (rock == null) loop, but that didn’t fix it either.