How do I make an objet invisible ? There are some objects that I want to make visible sometimes and sometimes not.
HTwarrior
How do I make an objet invisible ? There are some objects that I want to make visible sometimes and sometimes not.
HTwarrior
Yes a good one! I looked it up after reading your post because I want my objects to flicker when they are hit (arcade style). It seems the mesh renderer does not take a show/hide parameter, and add/remove the mesh render component by scripting seems like a bad idea, performance wise.
Anyone? :roll:
Strangely, ‘renderer.active = false’ doesn’t seem to actually hide the object. Instead, it seems to deactivate the whole object and causes scripts to break. It’d be more useful if it did hide the object, or if there were some other property for controlling visibility.
I’ve been making objects disappear by moving them far out of the camera view (either behind the camera, or simply anywhere beyond the camera’s far plane). That’s great for things with no rigid body, but it’s likely to mess up the simulation for objects which have one.
Here’s another off-the-wall idea: maybe it’s possible to hide an object by changing its material to one which uses a shader that causes the object to not be drawn. Not just to make it totally transparent, which is inefficient, but to stop it from being drawn altogether. Just a thought.
I think I will put my object far away from the camera view. Thanks
Htwarrior
Well the best way to make a object invisible (i think) is to just change it to a layer that the camera is not seeing. You certainly dont break script that way.
Bill
Good point. I’m glad someone’s awake, because I’m obviously not.
You type while asleep!? Neil I knew you had many talents but thats impressive.
Bill
How exactly could you do this? Can it be done with scripting? I’m trying to make an object that can be toggled visible/invisible based on the game state. Is there a way I can simply move it to an “invisibles” layer when it’s invisible and then move it back to it’s original layer when it’s visible?
thanx!
d
You just have to set the GameObject’s layer property to the number of the layer you want it to be in:
gameObject.layer = 9;
Look in Edit->Project Settings->Tags to figure out which number to use for each layer.
Thanx! This did the trick. Nice idea to switch between a layer that the camera doesn’t see.
I have to dig up this thread to ask if there’s a way to make an object invisible in the editor as well. I have a large controller object that kind of gets in the way when I want to see things (but it needs to be there). Any suggestions?
In Unity 1.5, the scene view has the layers popup - by default all layers are visible. But you can turn any of them off.
For making an object become invisible, you can just disable the renderer.
from scripting: renderer.enabled = false;
This will only change the object’s visibility. It will still get update calls etc…
Great. Thanks guys.