- Home /
How to make counter still counting after application has quit?
just like the building worker in clash of clan the counter still work when the app is closed .how to achieve that???
Answer by fafase · Aug 30, 2013 at 09:08 AM
I guess you want to do something like those game that keeps track of time even though you are not playing.
Well, the game is not running, the game stores the time you quit and stores only that. When you come back, the game compares what time it is now and what time was it when you left. Then depending on that time, it applies various changes.
In order to get the time you use the DateTime structure.
i have tried System.DateTime.now but i found that the time is dependent to machine.. so it is very easy to cheat the game.. any suggestion?? thx
Then you have to get the information from the net http://stackoverflow.com/questions/6435099/c-how-to-get-datetime-from-the-internet
thx for the replay,but the code in above link do not work in unity i got lots of error...
sadly, coding is more than copy pasting from the internet, you will have to read and understand what is being explained in the link and transfer that to unity code.
Answer by bubzy · Aug 30, 2013 at 09:11 AM
you could have a time based variable that is saved when you quit the app, and then when you reload the app you can calculate how much time has passed since it was closed, then run your simulation based on the amount of time that has passed.
So it takes 1 day to build a house, you start building a house then quit the app at 07.00, then you reload it at 19.00, when you reload the app you calculate that 12 hours have passed, this would mean that your house is 50% complete, you can then alter the current state of the building to 50% complete. there may be another way to do it.
thx for above 2 answer but what function can i use to achieve that? http://docs.unity3d.com/Documentation/ScriptReference/30_search.html?q=time cant found anything relevant to it..
To save stuff on the phone use PlayerPrefs You can use this class to store and retrieve your time
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
A node in a childnode? 1 Answer
How to Name Individual Buttons Within a List 2 Answers
Flipping textures 0 Answers
yield return WWW; not returning 1 Answer