- Home /
Question by
Benjim-Maccabomb · Apr 02, 2015 at 12:36 PM ·
collisionobjectoncollisionenterparentingunparenting
Unparent object on collision?
i am trying to make it where if you hit an object, a certain object that is parented to the main object becomes unparented, please help.
Comment
Answer by 334499p · Apr 02, 2015 at 06:31 PM
Could you be more specific about what object is which? Without much knowledge of your objects though, the following code removes an object's parent:
gameObject.transform.parent = null;
Answer by jcv8000 · Apr 02, 2015 at 06:35 PM
Put this in a script attached to the main object.
public GameObject theObjectToBeUnParented;
void OnCollisionEnter(Collision collision)
{
theObjectToBeUnParented.transform.SetParent(null);
}
Answer by UNZoOM · Apr 02, 2015 at 04:22 PM
var certainObject : Transform ;
function OnTriggerEnter (col : Collider) {
if (col.gameObject.name == "anObjectTrigger")
{
certainObject.parent = null;
}
}
Your answer
Follow this Question
Related Questions
Checking Object Collision Without Script 1 Answer
Making an object a child on collision 1 Answer
Detect collision with specified object 1 Answer
Ammo crate collision 2 Answers