Make multiple objects renderer off

Hi, i’ve come into a problem of having to turn off the renderer of multiple objects. What I mean by that is i’ve downloaded a model and in the prefab there are a large amount of objects each with a Mesh renderer and i’m wondering how to turn all of them off at once. If even possible. I’ve tried using

  1. var popup : GameObject;
  2. var trigger : GameObject;
  3. function OnTriggerEnter(col : Collider){
  4. if(col.tag == "Player"){
    
  5. popup.renderer.enabled = true;
    
  6. }
  7. }
  8. function OnTriggerExit(){
  9. popup.renderer.enabled = false;
  10. Destroy(trigger);
  11. }

and ends up saying "Assets/aScript/Popupp.js(13,15): BCE0019: ‘renderer’ is not a member of ‘UnityEngine.GameObject’. "

is there any possible way of actually doing what i’m trying to do? I’m willing to provide more details if needed.

1 Answer

1

You can’t access an Array like that. You need to loop through the array.

for (var i = 0; i < popup.length; i++){
popup*.renderer.enabled = false;*

}

//same for enabling

for (var i = 0; i < popup.length; i++){
popup*.renderer.enabled = true;*
}
Good luck :slight_smile:

hi, thanks for the response, do you mind explaining this to me? I'm a bit new to scripting and don't understand what an Array is ;-; also it worked! THANK YOU SO MUCH, I'VE BEEN TRYING TO FIND AN ANSWER FOR OVER A MONTH.

–