- Home /
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
Answer by Stelimar · Nov 29, 2009 at 03:23 AM
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!
Answer by Will · Nov 29, 2009 at 02:57 AM
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.
Answer by scorp · Nov 29, 2009 at 04:29 AM
Got it working! Thanks very much to you both. - S
If the answers were helpful to you, please vote them up and mark one of them as the accepted answer by clicking on the check-mark.
Your answer
Follow this Question
Related Questions
Pick Up like in Silent Hill 1 Answer
Windows Application 2 Answers
Move GUI elements. 0 Answers
GUITexture Button? 1 Answer