G
G
Gregory2562021-08-31 20:36:11
Unity
Gregory256, 2021-08-31 20:36:11

How to delete multiple objects?

Good day, please tell me how you can delete a parent if one of the children passes the check?
Impose a condition so that when a child is deleted, the parent is deleted? Verification occurs upon contact, I can’t think of a universal way. I understand that you can set it through the inspector and remove it, but this will greatly pollute the code.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BFGunner, 2021-09-02
@Gregory256

Well, let's say this:
*checking for a successful collision*
{
A = GameObject.Find(transform.parent.name);
Destroy(A);
}
It seems there is nowhere more universal.
Just don't forget to declare A as a GameObject.
This method should be hung on all child objects upon interaction with which the parent should be destroyed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question