• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by KnightRiderGuy · Sep 12, 2015 at 06:58 PM · timerdatascene-switchingsingletontimers

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KnightRiderGuy · Sep 12, 2015 at 08:32 PM 0
Share

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.

avatar image SarperS KnightRiderGuy · Sep 12, 2015 at 08:36 PM 0
Share

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.

avatar image KnightRiderGuy SarperS · Sep 12, 2015 at 08:43 PM 0
Share

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 ?

Show more comments
Show more comments
avatar image getyour411 · Sep 12, 2015 at 08:34 PM 0
Share

@zentaiguy - that's persist.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

28 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I implement a timer into this script that will record the total time the player has played. 2 Answers

Unity 5 - Time counter Up script (millisecond precision) UI 0 Answers

UnityOSC and timer 0 Answers

How to add a delay to a bomb explostion 1 Answer

resources loaded in one scene not transfered to other 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges