Hi I have a zombie like game and has a few scenes a title, the game, instructions, and scene after you died. In the game i have an extremely simple timer script that shows how long you have survived using Time.time. When you die you get taken to a scene that shows how long you have survived, a try again GUI.button, and a return to title GUI.button. If you click the try again one the time will not reset it will stay where you left off. Is there a simple way to reset it back to 0. I have tried making a boolean that is true if you clicked try again and in the timer script if it is true set the time to 0.0 but the time will just stay at zero because i didn't make it false again. Please help.
The Timer script
static public var time : float;
function Update(){
time = Time.time;
}
function OnGUI(){
GUI.Label (Rect (52,85, 200, 200), "Time = "+ time);
}
The Death scene script
#pragma strict
var customSkin : GUISkin;
var timeAlive : float;
function Update(){
timeAlive = Timer1.time;
}
function OnGUI () {
var buttonWidth : int = 400;
var buttonHeight : int = 150;
var halfScreenWidth : float = Screen.width / 2;
var halfButtonWidth : float = buttonWidth / 2;
GUI.skin = customSkin;
if(GUI.Button(Rect(halfScreenWidth - halfButtonWidth, 150, buttonWidth, buttonHeight), "Try Again")){
Application.LoadLevel("ZombieHunt");
}
if(GUI.Button(Rect(halfScreenWidth - halfButtonWidth, 450, buttonWidth, buttonHeight), "Title Screen")){
Application.LoadLevel("TitleZombie");
}
GUI.Label(Rect(halfScreenWidth - 250, 45, 500, buttonHeight), "You Survived for "+timeAlive+" seconds");
}
please help also if you have any suggestions to make it better
I have played with unity for a while and know most things but not all.
↧