- Home /
Hide GUI while switchcam
Hi,
I would like to hide all my GUI (using Unity GUI) when I switch of camera (for a cutscene).
I heard I could put the GUI on a layer and apply a culling mask on my camera, but can't figure out how to put my GUI on a different Layer.
Do someone has an idea on how to do this?
Thank you Very much!
Answer by The_r0nin · Dec 06, 2010 at 04:54 PM
private var inCutScene: boolean = false; function OnGUI(){
if (!inCutScene){
// Your GUI goes here
}
}
function BeginCutScene (){
inCutScene = true;
// your cutscene begins here
}
function EndCutScene (){
inCutScene = false;
}
Call BeginCutScene() when you start and EndCutScene() when you are done. No GUI...
EDIT
Or, as was suggested in the comments:
private var inCutScene: boolean = false; function OnGUI(){
if (inCutScene) return;
// Your GUI code here...
}
function BeginCutScene (){
inCutScene = true;
// your cutscene begins here
}
function EndCutScene (){
inCutScene = false;
}
This is the correct way of doing it, since Unity GUI is immediate-mode. You could simplify this by ins$$anonymous$$d of checking if(!inCutscene){doSomething();} but ins$$anonymous$$d saying if(inCutscene) return; at the top of OnGUI(). This will do the same thing, but is actually a lot easier to throw in and pull out while still maintaining clean code.
Good Point! I've edited my answer to show this option, as it makes very good sense.
Answer by oliver-jones · Dec 06, 2010 at 01:05 AM
You can deactivate the GUI on a particular camera in the Inspector. So just click on the camera in your scene that is the cut scene camera - and just deselect the GUI element.
I desactivated the GUILayer element of my cutscene camera, but the GUI still appears. I took care of desactivating my main camera and all other cameras during the cutscene, so it can't be the problem. Anyone has another solution?
OnGUI will still render when the GUI Layer component of a camera is there or not. Removing/disabling it only works for GUITextures/GUIText. OnGUI is drawn after all of the Cameras are rendered in that frame, and therefore is separate from the camera.
Your answer
Follow this Question
Related Questions
how can I disable all camera movements trough GUI? 2 Answers
Disabling/Hiding a Text Field with Enter Key 4 Answers
Render GameObjects over GUI.Layer 1 Answer
Is there a way to change the order of the "Layers" Tab? 0 Answers
GUI Buttons on a Mini-Map 1 Answer