- Home /
End Game When Time Is Up
How do you end the game when the time is up??? Here is my script right now.
private var startTime; private var restSeconds : int; private var roundedRestSeconds : int; private var displaySeconds : int; private var displayMinutes : int;
var countDownSeconds : int;
function Awake() { startTime = Time.time; }
function OnGUI () { //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 ("Time is Over");
//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 (43, 10, 100, 90), text);
}
How do I make it, so when the time hits 0, it takes them to a page that says: Game Over. (I will make the page and stuff) Please help! I am almost runner.
P.S. I will try to have the game on iPhone, so if you're interested on what you helped me with, the Game will be called Mountain Runner, and should be expected to be finished sometime this summer. Thx!
Answer by Mike 3 · Jul 14, 2010 at 08:44 PM
Easiest way would be to use a new scene for it, alread set up how you want it:
if (restSeconds == 0) {
Application.LoadLevel("Name Of End Game Scene");
}
Your answer
Follow this Question
Related Questions
when mouse pass over a button,the console print some content 1 Answer
Gui.Button over another gui.button 1 Answer
counting destoryed objects 2 Answers
Need Help Ending A Game - Alphabet Game 1 Answer
Timer Pause and Reset Issue 2 Answers