- Home /
How to record the real playing time?
Many games have such feature, in the save data, it shows how much time the player has played.
That means, in the save data, I have a variable called playTime. For example, when I opened this game for 5 minutes and closed, the playTime is 5 minutes; and next time when I play this game for 1 hour, the playTime would be 1 hour 5 minutes.
How do I achieve that?
Answer by Technicality · Jan 15, 2015 at 10:59 AM
The Time interface has ways to return the number of seconds the game or level has been running: http://docs.unity3d.com/ScriptReference/Time.html
You will want to make sure Unity saves that data when the game exits, maybe detecting that with OnApplicationQuit: http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnApplicationQuit.html
There are lots of ways you could save the data between sessions. The PlayerPrefs interface is probably the simplest though: http://docs.unity3d.com/ScriptReference/PlayerPrefs.html
In terms of converting that number of seconds value into something more human readable, in C# I would use DateTime: http://msdn.microsoft.com/en-us/library/system.datetime%28v=vs.110%29.aspx
But there are probably options in Unityscript/Boo that do the same thing.
Your answer
Follow this Question
Related Questions
How to Follow By Getting KeyDown? 0 Answers
A Few Questions :D 3 Answers
Save best time 1 Answer
saving total playtime of app? 1 Answer
How to measure the real time differential between application runs 0 Answers