How can I draw a GUI element for only one frame?

Is it possible to draw a GUI element for only one frame? If so, how?

This is how you would draw a Label for one frame after a Button is clicked.

var buttonRct  :  Rect    =   Rect(200, 200, 100, 40);
var labelRct   :  Rect    =   Rect(200, 300, 100, 50);
var buttLabel  :  String  =  "Show a label";
var labelText  :  String  =  "Peak-A-Boo!";

function OnGUI ()
{        
    if ( GUI.Button(buttonRct, buttLabel) ) {

        /* draw  a label you'll barely be able to see */

        GUI.Label(labelRct, labelText);
    }
}

Not quite sure why you would want to draw something for only one frame except for it to be either part of a puzzle or for subliminal messaging…

Also, I am assuming you mean camera frames (render calls). It wouldn’t make much sense otherwise.

This script must be put into a GameObject with a camera component

var triggered : bool = false; // Set this to true when ever you want to display
private var showing : bool = false;

function OnPreCull() {
    if (triggered) {
        showing = true;
        triggered = false;
    } else if (showing) {
        showing = false;
    }
}

function OnGUI() {
    if (showing) {
        //Render single-frame stuff here
    }
}

In theory, that should work (have not tested it). If you want to display for more than one frame, you will need to modify this a little. Again, this is for one visual frame. Update() will probably be called several times while the thing is being rendered.

You can have the script disabled normally, then enable it, wait a frame, then disable it again. This script waits one second, then enables the GUI for one frame:

function Start () {
	enabled = false;
	yield WaitForSeconds(1);
	ShowForOneFrame();
}

function ShowForOneFrame () {
	enabled = true;
	yield;
	enabled = false;
}

function OnGUI () {
	GUILayout.Box("Now you see me, now you don't");
}

You can call the ShowForOneFrame function whenever you want the GUI to be enabled for a frame.