Turn OnGUI to OffGUI

I am developing for the iphone but want to use OnGUI for its convenience, What I would like to do is set when OnGUI gets called.

Is there a simple way to do this?

I don’t know if there is a way of turning off a function, but you could enclose code by using a if statement:

function OnGUI(){
    if(drawGUI){
        //Draw GUI here
    }
}

Set drawGUI to false/true when you want to draw the GUI or not. If there’s another way, Im sure some is going to tell you.

I think this is what you want, maybe:

var showGUI : boolean = false;

function OnGUI(){

   if(showGUI == true){
      //do GUI in here
      if(GUI.Button(Rect(0,0,100,50),"Hello World")){
         showGUI = false;
      }
   }
}

Just using a simple on and off (boolean) will either activate or deactivate particular GUIs