[Android] When App closed get time when player was gone?

Hey,

I’ve been trying to get the player’s time when he was gone. We probably know those android/iOS games, like Cookie clicker, you get back online and you see how much you was gone for and whilest you weren’t there the game still played for you Automaticly, or those game were you went off and every 24hours you get a reward, and I don’t really understand how it works.

What I have currently is the opposite, the current time in seconds, and a pref that sets the time being online(This has to change to offline). On the start function I get the playerpref and multiple that with the score the player gets every second(When he is online) and than set that answer into a text.

So how do I change from what I have (when player is online) into when player is offline.

Thanks :slight_smile:

Make the application get the current time and save it to Playerprefs in OnApplicationPause, then retrieve and subtract the value with the current time in OnApplicationFocus to get the time elapsed.

To give a reward every 24 hours, save the time the reward was last claimed and check the time elapsed since, and re set the variable and give the reward if the time is >24 hours.

Sources: