Doing stuff once a day

Hi,

I’m trying to find out how to show ads to people 5 times every day (so they won’t get too annoyed)

Basically I need a value of shown ads to be resat every 24 hours - maybe by subtracting dates?

Thanks, Andreas :slight_smile:

Why not save the current date and the current count of ads shown to the PlayerPrefs and check if the date differs from the current date → Reset write date to the PlayerPrefs.
If the count is >= 5 do not show the ads.

What about something like this:

private DateTime _lastAdTime = DateTime.MinValue;

public void SellMeStuff()
{
     if (_lastAdTime.AddDays(1) > DateTime.Now)
     {
          // You can show a add now
          Debug.Log("Buy from me, please?");

          // Store for next time
         _lastAdTime = DateTime.Now;
     }
}

This will kick off your ad’s once a day. Instead of AddDays, you could also use AddHours, AddMinutes, AddSeconds, AddYears (hehe, not a great one if you want to make money).

if just save a date in PlayerPref it will be hacking easily
by just changing device date/time before get it.

so you need to connected to get time counter from your host
and then use it to calculate.