how to pop interstital once a day?

Hi,

How is it best to pop an interstitial ad once every day?
My interstital admob asset for unity works fine, it is more related to calling the function();

I was thinking to write to the player.pref the current date (System.DateTime) and then randomize if to display the ad after 1…3 gameover scenes so as not to annoy and not to be predictable.

However i was not sure if this is the best method
Thanks.

I guess you could use playerprefs and save the last day (date) the ad was shown, and if that's different from today, show that ad.

1 Answer

1

I am using this for a prize each day:

#pragma strict

private var currentDate : int;

private var DailyPrizeAmount : int;

static var ClaimThePrize : boolean = true;

	
function OnLevelWasLoaded(Level : int){

		if(Level == 5){

			if(PlayerPrefs.HasKey("IsFirstLaunch")){

				//Store the current time when it starts
				currentDate = System.DateTime.Now.get_Day();
				print("currentDate: " + currentDate);

				//Grab the old time from the player prefs.
				var oldDate : int = PlayerPrefs.GetInt("Day");
				print("oldDate: " + oldDate);

				if(currentDate != oldDate){
				
					ClaimThePrize = true;
					ShowPrize();
					print("The Prize is Right");
				}
			}
		
			//First launch.
			if(ClaimThePrize == true){
		
				ShowPrize();
			}
		}
	}
	
function OnMouseDown(){

		ThePrizeIsRight();
	}
	
function ThePrizeIsRight(){

		ClaimThePrize = false;
		HidePrize();	
		Save();
	}							
	
	
function OnApplicationPause(){

		Save();	
	}	
 
function OnApplicationQuit(){

		Save();
	}
	
function Save(){

		if(ClaimThePrize == false){

			//Save the current system time.
			PlayerPrefs.SetInt("Day", System.DateTime.Now.get_Day());
		 
			print("Saving this date to prefs: " + System.DateTime.Now.get_Day());
			//Debug.Log(Application.persistentDataPath);
		}
	}
	
function ShowPrize(){

		DailyPrizeAmount = Random.Range(100000,150000);

	}
	
function HidePrize(){

		Earnings.TotalEarnings += DailyPrizeAmount;
	}														
	
	
/*	
var theTime : String = System.DateTime.Now.ToString("hh:mm:ss"); 

var theDate : String = System.DateTime.Now.ToString("MM/dd/yyyy"); 

var theMonth : int = System.DateTime.Now.get_Month(); 

var theDay : int = System.DateTime.Now.get_Day();
*/