- Home /
how to put a timer on my game
this is how it goes. How will I be able to implement a timer that will trigger a specific action. for example. I have timer, when it reach 0 seconds a gui button will appear. I know to implement gui's but dont know how to put the timer that will trigger ta appearance of the gui and after it reach 0 seconds it will become 10 seconds again and it will count down again . any help? thanks
Answer by Nonakesh · Feb 19, 2012 at 01:30 PM
You could do something like this:
var countdown : float;
private var showButton = false;
function Update() {
if(!showButton){
countdown -= Time.deltaTime;
if(countdown <= 0){
showButton = false;
}
}
}
function OnGUI() {
if(showButton){
//Button
} else {
//Show Countdown
}
}
Time.deltaTime is the time in seconds it took to complete the last frame.
IT's used to make your game frame rate independent. This means that if you run your game on different devices with different hardware you will get the same result.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
can someone please take a look at this movement script? 3 Answers
How do I make a score script based on the time the player is alive? 1 Answer
Initiating several events on collision 1 Answer
teleporting player after time runs out 2 Answers