How to make ad available after some time ?
okay , so I want to make my ads only be playable every 5 minutes but i don't know how to make that..
public void ShowAd()
{
if (Advertisement.IsReady())
{
Advertisement.Show();
PlayerPrefs.SetInt("Coins", PlayerPrefs.GetInt("Coins", 0) + 500);
if (Controller.IsRunning == false) SetMenuScore();
}
}
this is the code I'm using.
Comment
Best Answer
Answer by corn · May 18, 2016 at 09:51 AM
You just need to check the latest time your ad was displayed. If it was less than 5 mins ago, do nothing ; else, display it.
[SerializeField]
private float m_IntervalBetweenAdsInSecondes = 300f;
public void ShowAd()
{
if (! Advertisement.IsReady())
{
return;
}
if (m_LatestDisplayedAdTime == -1f
|| Time.time - m_LatestDisplayedAdTime >= m_IntervalBetweenAdsInSecondes)
{
Advertisement.Show();
m_LatestDisplayedAdTime = Time.time;
PlayerPrefs.SetInt("Coins", PlayerPrefs.GetInt("Coins", 0) + 500);
if (Controller.IsRunning == false) SetMenuScore();
}
}
private float m_LatestDisplayedAdTime = -1f;
THAAAN$$anonymous$$$$anonymous$$$$anonymous$$SS VERRYY $$anonymous$$UUCH !!!! and sorry if it was dumb question , I am now learning. :)
You're welcome ! $$anonymous$$eep learning and enjoy.