- Home /
Timer Data Across Scene Changes
Ok been struggling with this for a while now. In my main scene I have a trip timer that can be started, paused and stopped and reset. When I go to another scene and then come back to my main scene I loose the time on the timer, I have heard that Singletons are a way to solve this. How would I do this using U.I. text?
Answer by SarperS · Sep 12, 2015 at 07:11 PM
Set your timer script to not destroy on load so it will persist between scene changes.
http://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html
Thanks Sarper but I don't want my timer to persist, I just want it to continue counting and keep accurate time when I return to the scene that has the timer in it.
Why not? $$anonymous$$aking it persistent is the easiest way. If not I would store the timer value and Time.time before changing the scene in two static variables. Upon returning to that scene I would assign (Time.time - storedTime) + storedTimerValue back to it.
I'm not sure I'm making myself clear. lol O$$anonymous$$ lets try this: I have a timer stop watch style in scene one or my main scene. I want for when I go back to my main scene for the timer to still be running and keeping an accurate "Count Up" of time.
I also have another one that can be set as a "Count Down" timer.
If I was to set them both and then leave that scene to go to another scene and then come back I would like them to have been running all during that time and keeping accurate to either Count Up or could down or both depending on if I have set one or both.
now I have heard that singletons are a way to do this but I am finding nothing on how to do any of that using UI text on canvases ?