- Home /
Help with a spawner script
Edit
How can I get a length of specific active gameobjects by a name instead of by tag in an update function? I know it takes longer, but I would rather that than make a ton of tags to search for. Specifically, I tag all of my enemy gameobjects "ReSpawn".
var locationOne:String; var enemyCount: GameObject[];
enemyCount = FindGameObjectsWithTag("ReSpawn")
How do I find and get a length all ReSpawns that might have a child object named 'locationOne'?
I need to continually check if ReSpawns found witha 'gameObject locationOne'.length < (x) or not.
Thanks for any help
Answer by DaveA · Aug 03, 2011 at 09:54 PM
Try to avoid using any 'Find' routine in Update. Best do that in Start and then manage the list if things are added/removed during play. Also try to use lower case to begin variables and upper case to begin functions.
Would you be able to use layers to help organize things?
Also consider http://unity3d.com/support/documentation/ScriptReference/Object.FindObjectsOfType.html
OppoCount will be an array of objects with that tag, so you can look for the name on each one like:
foreach (op in OppoCount)
if (op.name == "ThisSpot")
.. do something..
or
foreach (op in OppoCount)
foreach (t in op) // check children of the found items
if (t.name == "ThisSpot")
.. etc..
The second foreach example gives me error messages that t in op is not enumerable. The examples are directions for doing something to each of the children it finds, not exactly 'counting' them. I need a length to check, I don't need to actually DO anything to the gameobjects with the names I'm looking for. I'm trying to avoid making a whole bunch of tags.
Your answer
Follow this Question
Related Questions
Enemy spawner help with lengths 0 Answers
Multiple scripts with the same name issue 1 Answer
JS, get child 2 Answers
List all prefabs in project with a specific name 1 Answer
Spawn Multiple Monsters 1 Answer