Group of objects turning on and off

I’ve got a project with objects that I need to hide and make visible. I’ve got some scripts that will do this via alpha; but sometimes I’m working with large collection of objects, and assigning it to every single object would take quite a while.

Is there a way to make groups of objects invisible? Perhaps via Camera’s and layers?

can you use tags? then just have a single script on an empty that finds objects with tag x and turns the renderer on/off. layers could work too.

This is what the camera culling mask os for. Create a layer and put all objects that should be grouped together into that layer.

Now, to hide them all, simply disable the layer in the camera’s culling mask. Enable it again in the mask to show them again.

For docs, see:
http://unity3d.com/Documentation/ScriptingConcepts/Layers.html
http://unity3d.com/Documentation/ScriptReference/Camera-cullingMask.html

Cool. That sounds like just the thing.

To script that would I be able to use something like:?

camera.cullingMask.LayertoHide = false;

I didn’t understand all of the

// Only render objects in the first layer (Default layer)
camera.cullingMask = 1 << 0;

:sweat_smile:

Thanks.

For adding components to multiple objects, try this script: http://forum.unity3d.com/viewtopic.php?p=43697#43697

Yes, that can be kind of hard to follow. You might have better luck using a variable of type LayerMask, and then using .value to set the mask. Like this (untested):

var myLayerMask : LayerMask; // set this in the inspector

function Start() {
   camera.cullingMask = myLayerMask.value;
}

–Eric