- Home /
Removing a GUITexture a set amount of time after it has been enabled.
I've set up a simple achievement structure in my game, basically if the player gets 10 scoring objects without taking any damage they get a "ten in a row" achievement.
I've got it coded so the achievement icon comes up as a GUITexture and it plays a sound with the following code:
guiTexture.enabled = false; var Tada : AudioClip; private var played: boolean = false;
function Update () { if(scorer.scorz == 10 && LifeScript.life == 5 && !played) { played=true; audio.clip = Tada; audio.Play(); } }
What I would like to do and have so far failed at (I'm still in the early learning stages of Javascipt), is have it then disappear after 10 or so seconds so it didn't stay on the screen.
I know the answer is probably really simple, so I apologize for asking a newbie question, but all help is greatly appreciated.
Answer by Eric5h5 · Oct 15, 2010 at 02:54 AM
Update runs every frame, which is not efficient for something that only happens occasionally, and coroutines are good for scheduling sequences of events. Therefore I'd ditch that and use a coroutine for the score function, which would be in the global scoring script, and you'd call the function whenever you added a point to the score:
var tada : AudioClip; private var played = false; private var score = 0;
function AddScore () { score++; if (score == 10 && LifeScript.life == 5 && !played) { played = true; audio.clip = tada; audio.Play(); guiTexture.enabled = true;
yield WaitForSeconds(10.0);
guiTexture.enabled = false;
}
}
You'd have to reference the GUITexture some other way, unless the score script was on the GUITexture of course.
--Eric
Your answer
Follow this Question
Related Questions
guiTexture.enabled (am I an idiot???) 1 Answer
Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer
Move GUI elements. 0 Answers
GUITexture Button? 1 Answer
What's a great way to make a custom information window pop up 1 Answer