When my a box is clicked, I want it to destroy another object in the scene, and its parent. I know Destroy(gameObject) will destroy the object itself, but how would I destroy its parent and another object in the scene? Say the other object is call “blob”, what would the script to destroy the object, its parent, and blob? Advice would be great
All you need to do is get/find the other game object.
In the case of where the controlling game object created the other object just destroy it from there. If you need to find another game object use the GameObject.Find function. If it is in response to a collision or trigger event, use the collider or hit information to get the collider, and from there, it would be Destroy(other.gameObject);
I think something like this will work:
Destroy(this.transform.parent.gameObject);
Destroy(GameObject.Find(“blob”));
(can’t remember if destroying a gameobject automatically destroys children, you can find that in the docs anyway)
Thanks a bunch increpare, that was really helpful, and my game now works! In a few weeks time I’ll be posting it on the showcase part of the forum. Thanks again, that was really annoying me.
I’ve just read the documentation about that, and destroying a GameObject actually does destroy its children.
thanks so much