How to make a model invisible which has no mesh renderer ?

Hello everyone, I simply want my gun to be invisible, but the model I’m using just doesn’t have any mesh renderer ( I mean the parent doesn’t have, childs have renderers but there are a lot of child components ) or something like that. So when I try to say:

renderer.enabled = false;

It says : There is no Renderer attached to this game object…

My gun has a lot of children components like bolt,mag,pull, they have mesh renderers. So I thought about making it’s child component’s renderers invisible, but I can’t reach them. I tried this :

var renderers = gun.gameObject.GetComponentInChildren(MeshRenderer);

nothing happens, it doesn’t work. Then I tried this :

var renderers = gun.gameObject.GetComponentsInChildren(MeshRenderer);

and it says : UnityEngine.Component.enabled not found.

So I need help, any ideas ? Thanks :).

You probably just need to loop over all the MeshRenderers you got with GetComponentsInChildren and disable each of them individually since it gives you an array of renderers. See this thread.

Not sure if this is the best/right way to do it, but here you go… just change the call to however you’re wanting to do it, I’m putting it as hitting a key to do it on here->

var rendz : Component[] ;
var rendOnOff : boolean = true ;
function Start(){
rendz = gameObject.GetComponentsInChildren(Renderer) ;
function Update(){
      RendKiller() ;
function RendKiller(){
  rendOnOff = !rendOnOff ;
     for( var rend : Renderer in rendz){
         rend.enabled = rendOnOff ;

…should toggle renderers on / off when you tap the “L” key.