- Home /
Code to Set 3 ADS per day limit
Hello, Do you have a code that make you see maximum 3 ads per day and then it is refreshed? How do you guys implent such reward ads system ?
Thank you!
What have you done already? Can you post your code for us?
Answer by jasonlu00 · Sep 22, 2017 at 12:55 AM
You can save the timestamp and counter in PlayerPref.
private void PlayAD(){
int count = PlayerPrefs.GetInt("ADCounter", 0);
DateTime currentTime = DateTime.Now;
DateTime resetTime = DateTime.Parse(PlayerPrefs.GetString("ADResetTime", currentTime.ToString()));
TimeSpan travelTime = currentTime - resetTime;
if (travelTime.TotalMinutes > 1440f){//past one day
count = 0;
PlayerPrefs.SetString("ADResetTime", currentTime.ToString());
}
if (count < 3){
//Play Ad
count++;
PlayerPrefs.SetInt("ADCounter", count);
} else{
//Tell user to come back later
}
}
if you want to prevent people hacking your game very easily, there are some basic things you can do:
Get the current time from the internet:https://stackoverflow.com/questions/6676191/how-can-get-datetime-from-internet-external-resource-not-from-server
Use a more secure way to save data in PlayerPref: https://www.assetstore.unity3d.com/en/#!/content/32357
Your answer
Follow this Question
Related Questions
Keep score after restart & limit ads/hour 1 Answer
Limiting the time my gun can shoot 1 Answer
Minimum time between video ads?? 0 Answers
Setting a time limit 1 Answer