Need 2D image to appear onscreen n times then disappear

Hi, I'm fairly new to Unity and using the Lerpz tutorial project. I'm trying to get a 2D image to flash on screen 5 times then stop.

I'm able to get the texture to draw onscreen by calling GUI.Label from within the OnGUI function. But I can't find any docs or examples which show how to un-display something once it's been displayed. Any ideas?

Thanks, - S

Try something like this:

var showTime : int = 2;
var delayTime : int = 1;
var repeat : int = 5;

private var showImage : System.Boolean = false;
private var cycle : int = 0;

function Start() {
    FlashImage();
}

function OnGUI() {
    if (showImage) {
    	//Code to draw your image goes here
    }
}

function FlashImage() {
    while (cycle < repeat) {
    	showImage = true;
    	yield WaitForSeconds(showTime);
    	showImage = false
    	yield WaitForSeconds(delayTime);

    	cycle += 1;
    }
}

OnGUI is called every frame by unity. If showImage is true, the image will be drawn on screen, if it's false it won't. The FlashImage function sets showImage to true, waits showTime seconds, sets it to false, waits for delayTime seconds, and repeats repeat times.

Hope that helps!

Hm, have you seen this?

http://unity3d.com/support/documentation/ScriptReference/GUI.Window.html

If you go down to where it says

To stop showing a window, simply stop calling GUI.Window from inside your main DoGUI function:

im sure you can use the same principal for an image and put it on a timer or something similar, hope this helps a bit.

Got it working! Thanks very much to you both. - S