- Home /
Health bar depletes when app isn't open
I'm familiar with how to create a health bar the depletes over time within the app but how do I make this continue when the app isn't being used?
Think of an app similar to The Sims or a pet feeding game where you come back after an hour or so and the bar has depleted.
Answer by akillingbeck · Sep 06, 2017 at 11:02 AM
In OnApplicationQuit/OnApplicationPause or wherever you think is the best place for your game. Store the current time in player prefs, when your game starts again, check to see if that key is stored, if it is, calculate how much time has passed and set your health bar.
$$anonymous$$aybe worth mentioning that if you don't want people to be able to exploit this, then "the current time" needs to be obtained from something you know is reliable (eg a web service), rather than the system clock.