- Home /
Question by
adamchakov · Mar 01, 2014 at 04:41 AM ·
destroyparentchild
destroy Parent when child is destroyed
hey guys i wanna know how to destroy a parent when the child is destroyed , thanks !
Comment
Best Answer
Answer by robertbu · Mar 01, 2014 at 04:43 AM
This should work:
function OnDestroy () {
Destroy(transform.parent.gameObject);
}
@robertbu thanks fir the reply man but ,an error popped up , ""Can't destroy Transform component of 'GameObject'. If you want to destroy the game object, please call 'Destroy' on the game object ins$$anonymous$$d. Destroying the transform component is not allowed.""
He made a mistake, it should be Destroy(transform.parent.gameObject);
God this is too fast for my brain to work :p I replied and didn't had your edited answer here yet, this all happenned so fast...
yo thanks all , i fixed it my self xD , anyway you guys are awesome thanks a lot especially @robertbu
Your answer
![](https://koobas.hobune.stream/wayback/20220613135036im_/https://answers.unity.com/themes/thub/images/avi.jpg)