I’m sure this is pretty simple, but I can’t figure out how to destroy a parent object from a script attached to a child object. I’m trying destroy the whole chain. Any tips?
Destroy ( transform.root.gameObject );
That should work, unless there’s something blatantly obvious that I’ve forgotten…
1 Like
Thanks Sam… that did it. I had tried transform.root and transform.parent… I didn’t understand why it was treating it as a component, but I think I get it now.
This is because transform.parent is the Transform component of the parent game object and not the game object itself.
i got it …
Destroy(other.transform.root.gameObject);
Just for future people reading this - as a helpful tip thought I’d add this in here. vvv
This works for a whole chain of parents:
Destroy(transform.root.gameObject);
But if you just want to destroy the direct parent of the child you’d use:
Destroy(transform.parent.gameObject);
1 Like