Hi all, Should’ve introduced myself the first time I posted but was in a bit of a rush, and I apologise! I’m new to Unity and new to scripting, but getting thrown in at the deep end slightly, as we need to have a three screen demo up and running by Friday! So all help would be greatly appreciated!
I’m currently trying to build a button which toggles on/off a series of objects in the scene. I have managed to do this with the culling mask feature. However this only seems to work on one camera at a time. I have three cameras all visible at the same time, and I would like one button to hide an object on all three cameras at once. Can anyone help??! If you would like more information then please let me know.
Based on the context and title of your post, you simply want to toggle the visibility of an object. That can be done easily with the setting the following boolean on the target object.
renderer.enabled = false;
Here’s the link to it in the documentation.
Not sure though why you posted this in the GUI forum. Are you also having problems with the button?
Thanks Quietus, this makes sense and I had looked at this, but I have no idea how to apply this function to my button. Is there any chance you could give me a more obvious instruction on how to do this with a button.
In Unity’s immediate mode GUI, the button function returns a boolean which equates to it’s current state. So it would look something akin to the following.
function OnGUI () {
if (GUI.Button (Rect (xpos, ypos, buttonWidth, buttonHeight), "Make Object Invisible")) {
myGameObject.renderer.enabled = false;
}
}
The document is ripe with examples and suggestions on how the Unity GUI works.
It’s a bit of a shock if you’re used to event driven messaging based GUI’s. However once I got used to it I found I liked it a lot.
So I’ve came back to this after a long absence and just do not get it!
I need to be able to tolerate a whole range of POS (Point of Sale) on and off in a shop.
I have a prefab made with 20+ objects inside, all imported from Cinema 4D. The main prefab does not have a mesh renderer. So I decided to try and do this with a culling mask on a camera, I have two layers set up, a ‘not seen’ and a ‘seen’ When a button is pressed on the GUI it toggles between these two layers. Now the layers change but for some reason the objects are still visible, is this because I haven’t told it to include all the children? And if so how do I go about this?
Sorry for the long question, but I think the explanation was needed!