- Home /
 
 
               Question by 
               Premo36 · Jun 01, 2013 at 05:49 PM · 
                javascriptfunctiondisableongui  
              
 
              Disable function OnGUI after 4 seconds
I wrote a script that should disable after 4 seconds the OnGUI function, but when I tried, the function OnGUI still working after 4 seconds.
This is my JavaScript:
 #pragma strict
 var x : boolean = true;
 
 function Start () {
 yield WaitForSeconds(4);
 x = false;
 }
 
 function Update () {
 if(x == true){
 OnGUI();
 }
 }
 
 function OnGUI(){
 GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 400, 30), "What's that noise? It's was form the living room...");
 }
 
               Can anyone help me? Thanks!
               Comment
              
 
               
              Answer by Eric5h5 · Jun 01, 2013 at 05:50 PM
OnGUI is not something you call from Update; it runs by itself. You need to check if x (please use a better variable name) is false inside OnGUI.
Your answer
 
             Follow this Question
Related Questions
BCE0044: expecting (, found 'OnGUI'. 1 Answer
Event.type check doesnt work inside nested list 0 Answers
Disable script from code 5 Answers
OnGUI order, function executed before OnGUIs 0 Answers
yield WaitForSeconds(); issue--very specific, apparently 2 Answers