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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Timer based on a server time

Discussion in 'Scripting' started by kamuzai1226, Jul 10, 2014.

  1. kamuzai1226

    kamuzai1226

    Joined:
    Mar 11, 2013
    Posts:
    12
    I am looking for a way to keep a timer countdown based on the server and not the device. So for example the player wants to train speed, this will take 8 hours. In order to prevent the user from just changing their phone's time to +8hours and essentially bypassing the training time completely, it must be done based off of a server?

    So I guess now that I have written out the problem. Is there a way to create a time stamp based off of say, time.windows.com like our computers use to get the time they click "train" and then I can check time.windows.com when the person comes back on without them having to login and restart the countdown timer based on the difference of when they started it to when it must finish.
     
  2. Arunraj

    Arunraj

    Joined:
    Jul 4, 2012
    Posts:
    21
    Basically, you have to set up the some server communication on start of the game.

    For Eg:
    if the Player is playing the game and he/she has 8 hrs left to complete the task. In that case, when the task is started, you have ask server to record the time stamp of for particular task to the Player Name/ID. and in period of interval you have check against the server time and Elapsed time to complete the task and display the ETC. In case if player closes the game and restart after a while, do the initial check on game start.

    by this we don't have worry about the time change in devices.

    Happy Coding :)