- Home /
hide gui.label after an event
hi im using this script to serve as a timer and a game over script but when the timer hits zero, it still displays counting like 00: -1 00: -2 and so forth.
i have no idea how to hide the timer when it hits zero, any ideas? im a total newbie so please explain it a bit more thanks!
private var startTime;
private var restSeconds : int;
private var roundedRestSeconds : int;
private var displaySeconds : int;
private var displayMinutes : int;
var text : String;
//gui
var mySkin2 : GUISkin;
var gameover: Texture2D;
var permago: Texture2D;
var countDownSeconds : int;
function Awake() {
startTime = Time.time;
guiTexture.enabled=false;
}
function OnGUI () {
GUI.skin = mySkin2;
//make sure that your time is based on when this script was first called
//instead of when your game started
var guiTime = Time.time - startTime;
restSeconds = countDownSeconds - (guiTime);
//display messages or whatever here -->do stuff based on your timer
if (restSeconds == 60) {
print ("One Minute Left");
}
if (restSeconds == 0) {
print (stagegameover.gochecker);
gochecker = true;
stagegameover.gostate = true;
if(stagegameover.gochecker>2){
guiTexture.texture=permago;
guiTexture.enabled=true;
}
else{
guiTexture.texture=gameover;
guiTexture.enabled=true;
}
//stagegameover.tryagain=false;
//do stuff here
}
//display the timer
roundedRestSeconds = Mathf.CeilToInt(restSeconds);
displaySeconds = roundedRestSeconds % 60;
displayMinutes = roundedRestSeconds / 60;
text = String.Format ("{0:00}:{1:00}", displayMinutes, displaySeconds);
GUI.Label (Rect (400, 25, 300, 400), text);
}
Comment
Best Answer
Answer by Vonni · Jan 16, 2013 at 11:52 PM
Put this code under "function OnGUI () {"
if(restTime < 0){
return; // All code below is ignored as it, erm... returns! :)
}
Your answer
Follow this Question
Related Questions
Timer progress bar 0 Answers
Countdown Timer 1 Answer
GUI elements vanish when publishing 1 Answer
How do I hide GUI? 3 Answers