- Home /
Enabling/Disabling Multiple Tagged objects
I'm having a little trouble trying to disable some objects through a level controller script. Basically I've tagged multiple objects with the tag "zones" (they're triggers) and I want to disable all of them through a single controller script. Whenever I tried stating a var and then containing all the gameobjects within it with the "FindGameObjectsWithTag()" it didn't work, then I tried doing it in one line of code instead:
GameObject.FindGameObjectsWithTag("zones").enabled = false;
Any suggestions? It returns an error : "enabled is not a part of UnityEngine.GameObject", with both techniques. btw, I'm using the the line of code inside of an Update function.
Answer by Mike 3 · Jun 26, 2010 at 09:14 PM
That's because it's returning a gameobject array, not a single gameobject (and on top of that, it's active for gameobjects, not enabled)
you can do something like this:
for(var go : GameObject in GameObject.FindGameObjectsWithTag("zones"))
{
go.active = false;
}
So this'll work if I just cut & paste? Or do I have to rename a few things, or change something in a different area of script?
It should just work pretty much anywhere (within reason - it has to be compilable ;) )
I would like to note $$anonymous$$ike3 that you just solved my Camera Array problem!!!!! TY TY TY TY TY TY TY