- Home /
How can i make the game keep running in the background on android/ios ?
Hi i'm working on a simulation game, like Sims and SimCity etc.. where player builds a city or people whatever, and then comes back next day to get his income etc..please any help
Answer by lgarczyn · Oct 04, 2019 at 10:11 PM
It's pretty simple, on launch you need to get the date using System.DateTime.now
, compare it to a date you stored when the game last saved, and calculate the income for the time difference.
Thank you for the good idea ! sadly, I don't think it will work with my game because it will allow players to have a way to cheat by changing the Date on their mobile devices. am i right ? What I plan to do is create a multiplayer game and I will use the PlayFab server to store players' data and so on. The only problem is that the method of collecting money or gold in the game is through workers who do a movement and transfer between two building, there are also many variables are linked to elements that use OnTriggerEnter To disburse resources and transfer them from one element to another randomly Also the coordinates of the elements (people, animals,etc) and their numbers change depending on the activity I don't think that the time variable alone will do enough to calculated all the variables
You cannot force Android or IOS to keep your game awake, especially if it uses a lot of RA$$anonymous$$.
There is however another way than storing the date, and it is simply to send the date from the server to the application.
If you have a powerful server, it could keep updating the game in headless mode (no rendering), but that is pretty much overkill.
Just try to get the average time for a worker to get to his destination, and calculate that by hand. Or make your game independent from the Unity update system, and just run it really fast behind a loading screen.
thank you this sounds great ! if i can run the game fast behind a loading screen using time taken by the server I will check this solution, do you have any reference or tutorial about that ?