Timed events like plants growing and life generation - How

hi guys i am trying to build an offline game for mobile after completing the unity 2d course i want to implement a similar feature like wait time for life genration or watch ad to play now, something like that since it is offline how can i implement it so the user changing clock in his mobile will not affect it ,
how does similar games implement it so that timer run even when closed from the recent apps,

i hope you understand what i am trying to say ,

any guidance would be useful,

thanks,

Normally, you’d store the date and time that the timer starts. Then, if it should unlock after an hour, you would just check if it is an hour later. However, as you mentioned, players can change the time on their devices which means you have to manage it online. The game will send a request to a server and the date and time stored are that of the server instead of the device. Every time you want to check the elapsed time, you will have to get a new date/time from the server. Players can’t change the server time, so you eliminate that issue.

You also don’t have to have the time run all the time. When the game starts you can get the server time again and check how much time has passed since the start time was stored. If the timer was for 2 hours (like in your screenshot) and 3 hours have passed, the lock is unlocked. For the display you can just determine the remaining time and display it, using the device’s timer to count down, but you never rely on the device’s date or time. When there is nothing showing any timer, you don’t have to ‘run’ the timer

This is the way I would do it. There may be some other very clever ways of eliminating this issue, but I don’t know what that is

yeah i understand what you are trying to convey, but the issue is it is an offline game ,so we cant ping the server for date and time, the game i showed is tricky castle from play store , it is also offline game when i tried to change the system clock in my mobile it did not reflect in that game so wonder how they would have handled the situation,

is there any other way to handle the situation offline

thanks in advance,

Mobile games are almost never offline. They check for updates, log into accounts, download ads, etc. From the little bit of research I’ve done I found no other way. If you’re going to use an ad to ‘open now’, your game is online, even if you say it’s not.
There were some suggestions of trying to hook into the GPS and use its clock because a GPS’ clock has to be accurate in order to work so it will be updated from a time server, and it will not be changeable by a user.

this is the situation i want to get cleared ,user plays several levels ( offline ) and is prompted with wait time to play further or watch ad to play now , but if user did not turn on his mobile data or wifi and changed the clock in his mobile will it affect the timeshown, because i cant access the servers without internet, when user opens the game with internet turned on i will fetch datetime from servers if he user did not do that how would i manage it,

thanks in advance

You can’t. You can’t fetch ads so the ‘open now’ cannot work, and you can’t be sure the user did not change the device time unless they changed it to ‘before’ the last time you stored. then you’ll know, but you can’t figure out what the correct time should be

thanks for clearing that up , i cant show ads that is understandable , but what will happen to the timer, if i dont make request to the server and compare it ,

kindly test with the game tricky castle you will understand what i am trying to say ,

I know what you are trying to say. This post on stackexchange looks promising but since I don’t do mobile games, I am not sure how much of that you will be able to access from Unity

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms