How do i play an ad every third time i press an button?
The title says it all, how do i play an ad every third time i press an button?
Answer by shrey150 · Oct 07, 2017 at 10:06 PM
Use PlayerPrefs.SetInt()
to save an ad count variable, then read that number using PlayerPrefs.GetInt()
before you want to play an ad. Use adCount % 3
to check if it's the 3rd time, and show an ad. Then just iterate that number with PlayerPrefs.SetInt()
and set it to adCount + 1
. Hope this helped!
Could you be more specific? Or show an example of sorts. Here is my ad script i have right now:
public class PlayAD : $$anonymous$$onoBehaviour {
private void Start()
{
Advertisement.Show ();
}
public void showAD()
{
if(Advertisement.IsReady())
{
Advertisement.Show ();
}
}
}
Sorry my answer was broad, I was on my phone. Try something like this:
void ShowAd() {
int adCount = PlayerPrefs.GetInt("Ad Count");
if (adCount % 3 == 0 && Advertisement.IsReady()) {
Advertisement.Show();
PlayerPrefs.SetInt("Ad Count", adCount + 1);
}
}
I'm sorry but this doesn't work for me, it just plays the ad the first time i press the button and it never plays it again.
Your answer
![](https://koobas.hobune.stream/wayback/20220612140514im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I put ads in my games and profit? 2 Answers
Unity ads working on device, not working in editor 1 Answer
Test ad still showing up. 1 Answer
Unity Ads Error 0 Answers