hi,
I have imported an object from 3dmax and all the materials and mesh renderer are mapped to different items. But i need to apply visibility (renderer.enabled) to all these items. I dont need to copy the same script to all the elements one by one. Is there any other way of doing it
Thankx
To do so, have one script which references all the renderers you want to change.
public Renderer[] renderers;
public void SwitchRenderers(bool onOff)
{
foreach(Renderer render in renderers)
{
render.enabled = onOff;
}
}
Then, you put this script on your top level object, and assign all the rest of the renderers in the inspector (drag-and-drop). When you want to turn the renderers on or off, use
bool setEnabled = true /* or false, whatever*/;
topLevelGameObject.SendMessage("SwitchRenderers", setEnabled);