- Home /
My timer freezes everytime I leave the scene and come back.
my timer code:
#pragma strict
private var initialtime : float;
private var texttime : String;
var CountMinutes : int;
var CountSeconds : int;
private var restseconds : int;
private var minutes : int;
private var seconds : int;
var guitime : float;
function Start () {
initialtime=Time.time;
CountSeconds = CountSeconds + (CountMinutes*60);
}
function OnGUI () {
guitime = Time.time - initialtime;
restseconds = CountSeconds - guitime;
seconds = restseconds%60;
minutes = restseconds/60;
texttime = String.Format("{0}:{1}",minutes, seconds);
GetComponent(GUIText).text = texttime;
if(seconds <=0 && minutes <=0)
{
//Pause the game
Time.timeScale = 0;
DontDestroyOnLoad(GameObject.Find("Diamond"));
Application.LoadLevel("Score");
}
}
I have this script on another object that loads a new scene then in that scene there is a button that lets me go back to the timer scene again then when I am in the timer scene the timer just doesn't move. I don't get why. But theres this other button that loads another scene and if I return to the timer scene the timer would work fine. Does anyone have any ideas? Thanks
Answer by Woj_Gabel_FertileSky · Sep 01, 2014 at 11:04 AM
Check if the Start method is called every time a scene loads. Things dont get called when you use DontDestroyOnLoad() method.
So do you mean putting the DontDestroyOnLoad in a separate function?
Can I have a proper answer why isn't anybody answering?!?!?!?
Dude, i gave you an answer. Think for yourself. If you give me changed code, or any other sign of your commitment to your code, i will help ypu. But dont be that guy, dude, not cool.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
BCE0049 error with network script 0 Answers
Weird thing with my script :/ 1 Answer