D
D
Dmitry Korolev2017-07-17 23:03:16
C++ / C#
Dmitry Korolev, 2017-07-17 23:03:16

How to remove all th with the same name from the scene?

How to remove all th with the same name from the scene? It's not clear if they are currently on or not.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Victoria Viver, 2017-10-05
@adressmoeistranici

as mentioned above, it is best to initially make them children of one.
if a certain script is attached to all, then you can search by type - FindObjectsOfType
if you set a unique tag, then you can search by tag - FindGameObjectsWithTag
if none of the above is suitable, then the most expensive way remains - to search by type (as in the second option ) GameObject and check the name of each found object:

foreach (var gameObj in FindObjectsOfType(typeof(GameObject)) as GameObject[])
{
    if(gameObj.name == "bar")
    {
        //Do something...
    }
}

V
Vladimir Alkhimenko, 2017-09-13
@AngryProgrammer001

The easiest option is to make them children of one, and then just go through the children and delete them

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question