x


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

more ▼

asked Nov 29, 2009 at 02:53 AM

scorp gravatar image

scorp
2 3 2 3

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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!

more ▼

answered Nov 29, 2009 at 03:23 AM

Stelimar gravatar image

Stelimar
4k 19 29 64

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Nov 29, 2009 at 02:57 AM

Will gravatar image

Will
423 21 18 32

(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Nov 29, 2009 at 04:29 AM

scorp gravatar image

scorp
2 3 2 3

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.

Dec 08, 2009 at 09:29 AM runevision ♦♦
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5912

asked: Nov 29, 2009 at 02:53 AM

Seen: 2425 times

Last Updated: Nov 29, 2009 at 02:53 AM