- Home /
How do I set a limit to how many ads a player can watch each day.,How do I limit a player to watch 6 ads per day?
Hi. I have a game with adverts, and I want to limit players to only watch 6 adverts per day. Is the a way to script this in my game?,Hi. I'm trying to set a limit to how many times a player can watch an advert on my game. Then I want this to reset when a new day begins.
Answer by Z_Y_X · Jul 18, 2020 at 01:26 PM
You need to use PlayerPrefs:
int watchedAds=0;
int daySince1900
void Start()
{
watchedAds = PlayerPrefs.GetInt("watched Ads", 0);
daySince1900 = PlayerPrefs.GetInt("days", 0);
if(daySine1900 != nowDay)
{
watchedAds=0;
}
}
void ShowAd()
{
if (watchedAds > 6) return;
watchedAds++;
...
}
void OnDestroy()
{
PlayerPrefs.SetInt("watched Ads", watchedAds);
PlayerPrefs.SetInt("days", nowDay);
}
nowDay - number of day since 1900.
Microsoft Documentation:
https://docs.microsoft.com/en-us/dotnet/api/system.datetimeoffset
documentation for PlayerPrefs: https://docs.unity3d.com/ScriptReference/PlayerPrefs.html
Your answer
Follow this Question
Related Questions
How to integrate heyzap without conflicts ? 0 Answers
Are Unity Ads country restricted !! 0 Answers
My ads wont show up after i uploaded it to google play 0 Answers
Reliable way to track remaining advertisement videos? 0 Answers
Unity Ads with cooldown 1 Answer