cdytoby
1
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?
The Time interface has ways to return the number of seconds the game or level has been running:
You will want to make sure Unity saves that data when the game exits, maybe detecting that with OnApplicationQuit:
There are lots of ways you could save the data between sessions. The PlayerPrefs interface is probably the simplest though:
In terms of converting that number of seconds value into something more human readable, in C# I would use DateTime:
But there are probably options in Unityscript/Boo that do the same thing.