Hello. How can I destroy all objects with a certain tag?
I tried to do something like this, but It doesnt work.
EDIT -Updated the script, still doesnt destroy all of the objects with that tag.
You just need to iterate through the array elements instead of trying to access the array itself.
So, instead of
you will need to use
answered Nov 29 '10 at 07:26 AM
This is also in answer to your similar question here.
You can acquire an array of references to all the active game objects in the scene with a specified tag using GameObject.FindGameObjectsWithTag(). Once you have this array, you can check its length to see how many such objects there are.
You can also perform operations on the list of game objects as needed (for example, destroy them all using Destroy(), activate or deactivate them, enable/disable specific components, etc.).
answered Nov 28 '10 at 10:40 PM