Reputation: 199
During my game the user gets rewards every 10 minutes.
Even if they leave the app/game, when they come back, if 10 minutes has passed, they still get their reward.
So lets say for example: the user is playing and leaves the game with 5 minutes left until the next reward.
The user then leaves the game and returns an hour later.
How would I go about seeing if the 5 minutes have passed since the last open?
Does anyone know how to do this? I am using unity.
Upvotes: 1
Views: 2499
Reputation: 3469
Ian answer is OK but it has one problem, if user change the system (PC, mobile, ...) date and time, lets say add one year to the date, when he come back to game, he will get zillion reward unfairly! I think current dateTime must be recived from a ntp server
instead of DateTime.Now
.
Take a look at this answer : How to Query an NTP Server using C#?
Upvotes: 1
Reputation: 30813
You may want to use DateTime
struct
, especially its DateTime.Now
.
When your player leaves the game save the date time:
DateTime leaveDateTime = DateTime.Now;
//Store leaveDateTime value
When your player resumes,
//load leaveDateTime value
TimeSpan diff = DateTime.Now - leaveDateTime;
Then use your TimeSpan
values (check TimeSpan.TotalMinutes
) to give reward to your player.
if (TimeSpan.TotalMinutes >= 5){
//Give rewards for your players
}
Upvotes: 1