The script i built up is supposed to create gameobjects in a loop, in this case, 10 gameobjects; but only one is created, and i can’t access it’s name… I’ve searched and my code looks right to me, so, any idea what’s wrong with it?
public string systemName = "Yulu";
public Color sunColor = Color.white;
public Transform planetPrefab;
private int planetAmount = 10;
private int planetOffset = 81920;
private float tempPos = 81920;
ArrayList planets = new ArrayList();
void Start ()
{
sunColor = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f), 1f);
for (int i = 0; i < planetAmount; ++i) //10 is the max planet amount, this can't be more.
{
print (i);
if (Random.value <= 0.5f)
{
GameObject planet = (GameObject)Instantiate(planetPrefab, new Vector3(0, 0, tempPos), Quaternion.identity);
planet.name = systemName + "-" + i;
planets.Add(planet); //network
planet = null;
}
tempPos += planetOffset;
}
}
And yes, i dragged the prefab to the script in the inspector.