- Home /
How do I make my timer start and stop when on certain levels?
I'm making a simple FPS for an assignment I have a start screen, instructions, my level and a game over screen, the problem is that when I start my game on the start up screen the timer has already begun on my main level. also if I start from my level and skip the start screen it carries on after it has reached zero, ive made it take me to the game over screen when the timer reaches less than zero but this does not stop the timer from continuing to count down. Please help
Here is my script so far
pragma strict
var startTime:float; var timeRemaining:float;
function Start () {
startTime = 5.0;
}
function Update () {
Countdown();
}
function Countdown(){
timeRemaining = startTime - Time.time;
ShowTime();
if(timeRemaining < 0)
{
timeRemaining = 0;
TimeIsUp();
Debug.Log("Time remaining = "+ timeRemaining);
}
}
function ShowTime(){
var minutes: int;
var seconds: int;
var timeString : String;
minutes = timeRemaining/60;
seconds = timeRemaining%60;
timeString = minutes.ToString() + ":" + seconds.ToString("D2");
guiText.text = timeString;
}
function TimeIsUp(){
Application.LoadLevel(3);
Debug.Log ("Time is up");
}
Answer by AlucardJay · Oct 22, 2013 at 02:51 PM
line 18 should be :
timeRemaining = startTime - Time.deltaTime;
Your answer
Follow this Question
Related Questions
Time does not start counting down when need to 1 Answer
CountDown Timer Help (Seconds problem) 2 Answers
Start timer with trigger 1 Answer
did not QUIT when the Time is over ...? 1 Answer
Timer to measure game length 2 Answers