In my game I have watch video earn coins system, now I want to program a delay so the user cant watch the video every 5 seconds, for example I want to let him watch every 6 hours, but I'm not sure how can I do that, how can I program a timer that will count down even if the app is closed or how does this kind of timer work, I mean everyone saw this in many games where they count down days or hours until some gift or something. Any help is appreciated.
Take the 2-minute tour
×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.
There is few ways to do this. Store information of last gifting time to:
File writing method is quite simple to do.
Now, if this is very important to keep player doing this over and over again, you cannot store that time as a plain text. You have to use something to scramble it. |
|||||||||||||
|
Below code will do what you want. You will need to save and load the value of "DateTime lastPlayDate" between sessions. using System; public class GameManager : MonoBehaviour { DateTime lastPlayDate; void Start() { lastPlayDate = DateTime.Now; } void Update() { DateTime currentTime = DateTime.Now; TimeSpan timePassed = currentTime - Convert.ToDateTime(lastPlayDate); if (timePassed.TotalDays > 0 timePassed.TotalHours > 0 && timePassed.TotalMinutes > 1) { Debug.Log("Well that went quick..."); } } } |
|||
|