- Home /
How can I show/hide all models in a GameObject?
I'm making a FPS game, and I want to hide any weapons the player isn't using.
I tried using "renderer.enabled", but I get an error saying there's no "Renderer" to access, so I added a renderer component, and I got no errors, but nothing happened to the object, the renderer was set to "false", but the object was still there.
My GameObject consists of multiple models, is there a simple way to hide them all? Solution perferably in C#.
Answer by DaveA · Dec 12, 2012 at 11:30 PM
GetComponentInChildren(Renderer).enabled = false;
or
Renderer[] rs = GetComponentsInChildren<Renderer>();
foreach (Renderer r in rs)
r.enabled = false;
I had an error when I put it in, then I figured it out, that was Javascript, I was using C#. I converted it, and it worked!
However, it only worked for one of the models, I forgot to mention (because I didn't think it made a difference), is that the GameObject I'm trying to hide consists of multiple models, is there a simple way to hide them all?