- Home /
Question by
Bearukun · Apr 17, 2014 at 02:24 AM ·
prefabchildchild-to-gameobject
Adding child to a instantiated prefab.
Hi guys, I've been spending countless hours now with a problem that I can't get over without some help.
The basic idea behind the game is that I'm trying to make it so that I have this gameObject that, at some point, will spawn 3 additional bricks inside of it - I can get one bricks to spawn, but..!
void CreateBlock(){
b1 = Instantiate((blocks[Random.Range(0, blocks.Length)]), new Vector3 (-1.99f, 10.69f, 0), Quaternion.identity) as GameObject;
b1.transform.parent = this.gameObject.transform;
}
But the problem that I'm having is that I can't add the block I'm instantiating as a child to the prefab that I have added the script to.
I have zipped the project here, https://dl.dropboxusercontent.com/u/1148172/Zatch.zip if some kind soul would take a look at it.
Cheers.
Comment
Looking at your code, it looks as if you are only instatiating a monobehaviour, try (blocks[Random.Range(0, blocks.Length)]).gameObject