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!

3 Answers

3
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 instead of checking if(!inCutscene){doSomething();} but instead 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.

–

anybody knows how I could do this?

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.

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.

–