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!

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.