Is it possible for me to make an object a child of another object when a certain button is pressed, and vice versa?
I know how to use input, just need to know how to add/ subtract children from script.
Is it possible for me to make an object a child of another object when a certain button is pressed, and vice versa?
I know how to use input, just need to know how to add/ subtract children from script.
Do you mean: childObject.transform.parent = parentObject.tranform
@always_beta means that objOne and objTwo are GameObject references. Contrary to Flash and web javascript, in Unity the object name cannot be used as a reference to the object - Unity uses reference variables, which are the equivalents of C pointers - a reference holds the object address in memory (kind of… things are somewhat different in .Net/Mono).
In the case above, theCollision gives you several references to the object hit (gameObject, transform), which you can use to set parenthood:
function OnCollisionEnter(theCollision : Collision){ if (theCollision.gameObject.name == "item"){ if (Input.GetButtonDown("Pick Up")){ // Collision has a reference to the object's Transform as well // You must use it, since parent is a Transform property: theCollision.transform.parent = transform; } } }