I’m currently working on a game on iPhone with resources regained over time like a few game already do. I was wondering how do you make a countdown that continue while the apps is closed. I’ve read about the System.DateTime.Now that tell you the current real time on the machine but it never seemed to work like I wanted. If someone could give me hints or like me to a similar thread, it would be really appreciated because all I’ve found for the moment is how to make a basic timer…
System.DateTime.Now.ToUniversalTime(); this function returns the current time in a universal format. what you have to do is save it to local file (or playerprefs) and reload it back when you open the app again get the time using the same function. Now is you find the difference between these you will get the time offline, subtract it from the countdown time you have saved early to the local. The difference will be in System.TimeSpan so should know abt tht too
example:
this code i used to retrieve the difference in minutes
Try to store time from internet source when application closes and on application load get time again. After this make your desired computation for gained resources.
You can extend this idea to hash/crypt time in player preferences along with comparision of time on device to be sure user does not cheat.
If watching time is crucial for your app you must be carefull about not let app fooled by user. i think that online time check is cruial for this.