Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Game Process when player is not in game...

Discussion in 'Scripting' started by SquirrelGames, Mar 27, 2018.

  1. SquirrelGames

    SquirrelGames

    Joined:
    May 25, 2017
    Posts:
    2
    Hi! What methods can I use to change game progress when people is not in game?For example collecting coins from mine like in Clash of Clans or Fallout Shelter...?
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    I don't know those games, but one way would be to check the time when the player next opens the game and handle any updates based on that.
    Perhaps there is a list of ongoing activities that have end times, or perhaps there is an interval to earn your coins, and from the current time you can work out the number earned.
     
    Nigey likes this.
  3. McDev02

    McDev02

    Joined:
    Nov 22, 2010
    Posts:
    661
    Usually these games use servers to calculate these things. So each time the player logs in the server compares login time and add coins accordingly to that time. Nowadays I think this happens in regular updates like the app connects to the server in the background or the server updates each user in given intervals. That way you are invited to open the App again (Push message).
    Anyway solution A which is the most secure uses a server to calculate and store data like this.

    Another solution is to use the local machine by e.g. comparing System time. But this is prone to cheating by simply editing a file or the devices date/time :)
     
  4. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    That's your best get IMO as well. Clash of Clans will be using an online server somewhere and actually getting the timers from API queries online. However Fallout Shelter might be doing something similar to this version. If there's a set interval, create a 'last time activated' datetime and a 'refresh duration' datetime. You can calculate the number of times it can activate since the last time used. You can use a similar system for any kind of cooldown timer that has a relatively long duration outside play time. Just make sure to save your times somewhere, like a serialized class.

    Alternately if you're doing an online game that requires timers, you'll need some form of API on your server that you can send 'used this thing that has an online timer on it' and potentially a callback event system to notify the application that. Or alternatively from a callback event, make an assumption of time on your local application, and once the timer's up or about to be up, validate that on the server. More than likely this system is overkill, unless you have multiplayer or many online features.