- Home /
Question by
0867532 · Jul 27, 2013 at 02:56 PM ·
gameobjectremove
How to get all game objects and remove some of them..
I have game objects with names like 1, 2, 3 e.t.c. with tag "BOSS" i need to remove objects, that have names < 8 for example. and current counter varible is 10... HOW??? hope you can help, thx.
Comment
So I'm going to assume you don't have a list or array of the objects named numerically.
So first, find all objects tagged with Boss : http://docs.unity3d.com/Documentation/ScriptReference/GameObject.FindGameObjectsWithTag.html
Then loop through all the returned gameObjects, convert the name to an integer, then check if it is less than 8 :
for ( var go : GameObject in returnedObjects )
{
// convert name to integer
var nameInt : int = parseInt( go.name );
// check if it is less than 8
if ( nameInt < 8 )
{
// remove object
}
}
Your answer
