Hi there. I need some help. I want to put a cube inside a cube. Through code. I know it is possible through dragging or just adding game object inside it, but I need it to happen through code. It’s like adding a Gui texture through code. Please help me guys. Thank you in advance!
You mean you want to make the object a child of another object?
Something like this
GameObject myParent;
GameObject myChild;
void Start() {
myParent = GameObject.Find("CubeOne");
myChild = GameObject.Find("CubeTwo");
}
void Update() {
if(doSomeStuff)
{
myChild.transform.parent = myParent.transform;
}
}
I don’t know what you mean “in”. Do you mean physically inside or just parent child?
^^^^^ he already posted the parent child method, so I will show you the physical method.
#pragma strict
var littleCube : GameObject;
function Start () {
Object.Instantiate(littleCube, gameObject.transform.position, gameObject.transform.rotation);
}
put this script on the BIG cube, then put the little cube in the “littlecube” slot in the inspector. At the start of game the little cube should be at the center of the big cube.
It’s physically inside. I have a cube and it is seen inside. I want to put an imported .obj object inside the cube. Is the code that you’ve given can be put in the imported obj?
There is no “littlecube” slot in the inspector. why?