Hello, I have a loop and i want to make some clones as children of gameObject “spawnpoint” within the loop.
I have read alot of topics and tried lines like this:
var ino = Instantiate(blocks[Random.Range(0, blocks.Length)], Vector3 (x,y,z), rot);
//ino.transform.parent = GameObject.Find("spawnpoint").transform; ???
//ino.transform.parent = spawnpoint.transform; ???
Thanks!
You need to change this
//ino.transform.parent = GameObject.Find("spawnpoint").transform; ???
//ino.transform.parent = spawnpoint.transform; ???
to something more like this
//find the spawn point and store it into a var
var spawnpoint : GameObject = GameObject.Find("spawnpoint") as GameObject;
//set the parent of our instantiated object to spawn point
ino.transform.parent = spawnpoint.transform;
Also, as a side note, DO NOT use GameObject.Find() in a loop or an Update function if you can avoid it. Before the loop starts, call find ONCE and store it’s result into a var, and then just use that var directly.