I have 2 cameras in a scene one with a hud and another that has a control for the music player. When I switch cameras the gui objects of the first camera are still visible on the second camera even though I have disabled the first camera.
The second camera has none of the gui objects of the first camera assigned to it. How do I solve this ?
var Camera1 : Camera;
var Camera2 : Camera;
private var thisCamera : Camera;
function Start ()
{
thisCamera = Camera1;
Camera2.enabled=false;
}
function switchCamera()
{
Camera2.enabled=true;
Camera1.enabled=false;
Camera2.camera.enabled=true;
Camera1.camera.enabled=false;
thisCamera = Camera2;
yield WaitForSeconds(4);
Camera1.enabled=true;
Camera2.enabled=false;
Camera2.camera.enabled=false;
Camera1.camera.enabled=true;
thisCamera = Camera1;
}
Use layers, and put the GUI elements for camera1 on one layer, the GUI elements for camera2 on another layer, and set the camera culling masks as appropriate.
They won’t care about you disabling any camera as they are not bound to cameras at all.
OnGUI is GUILayer dependent, not world rendering.
Disable the guilayer on the cam you want to render the ui and remove / disable it on the other.
Also, write your gui code clean and not as hacky with hope for “automagic” as you likely did it now.
Have a state machine that tells your gui system what it is meant to show at a given time.
means if you switch to cam 2, tell it to hide anything but the media player.
if you switch to cam 1, tell it to hide the media player and show the rest.
Or just use a single camera and handle it with the states there.
I’ve just run into this problem too. My problem is that I want to draw some GUI elements on one camera and most on another camera. So disabling the GUILayer on one camera is not possible.
How can I set things up so that some GUI controls are drawn on the first camera and the rest on the second? It’s important that they are not drawn on both. (I’m drawing some beneath the scene and some on top.)
By the way, if this is true, the documentation needs updating as it says:
I explained above, but to rephrase: Use layers combined with appropriately set culling masks on the cameras. i.e., have Camera1 and Camera2 layers and put the GUI controls for the first camera on the Camera1 layer, and make sure the second camera doesn’t display the Camera1 layer, and vice versa for the first camera. This won’t work with OnGUI, but only GUIText/Textures.
It’s not true. The documentation is correct; the GUI Layer component is for GUIText/Textures only and has no effect on OnGUI.