The game has int changing the score and coroutine, it has a while which increases the score by 1 every second.

How to realize that the score increased in the off game. So I started the game let's say in an hour and the score has increased by the right amount.

What ways is implemented in games? And where to read about it?

  • 6
    Remember the starting date of the score. at any time you can calculate the difference in seconds between the beginning and the current, which will give you the desired value. Always yours, cap) - morphey83
  • @ morphey83, format your comment as an answer. Very well working option. - Alexander Danilovsky
  • @ morphey83 you can show a sample code - NoobCSharp
  • And if the character for some reason stopped to drop points? - nick_n_a
  • What is there to show? How to deduct two dates? ((TimeSpan)(d1 - d2)).TotalSeconds - nick_n_a

1 answer 1

You can remember the starting date of the score. At any time you can calculate the difference in seconds between the beginning and the current moment, which will give you the desired value.

PS

And if the character for some reason stopped to drop points?

With a full value, you can always implement any logic in score calculations. But there are nuances: by moving the system date, you can "accidentally" win)) but this is another story ...

  • Only there is one problem. A clever user can cut down the 'Net, and rewind time if the game is not online - Aqua
  • @SeeSharp, I’m not a connoisseur of game design, but I think it’s about a learning example, rather than a real project. Most likely, a real project would be protected from such a “fraud” by checking the connection + encrypted channel + server accounting. Your doubt is quite appropriate, but has already been reflected in my answer. - morphey83
  • Yes, it seems, it is enough to store and use server time, and not the client, to avoid such a problem. - Lunar Whisper
  • @SeeSharp, so you can ask the server for the time, not the user's smartphone :) - RiotBr3aker
  • @ RiotBr3aker here, another thing) - Aqua