- Home /
admob repeating infinit times can't stop
hi, i can't stop the ad interstitial showing up after first time, it continuos at infinity even in the debug it's going crazy, i'm trying to show up only on death of the player, it mean at "GAME OVER", but it doesn't stop at that. i want to show up only 3-4 times after death or maybe every 5 minutes
using System.Collections;
using UnityEngine;
using GoogleMobileAds.Api;
public class AdScript : MonoBehaviour {
InterstitialAd interstitial;
private void Start()
{
RequestInterstitial();
}
void Update()
{
if (GameManager.isGameOver)
{
showInterstitialAd();
}
}
public void showInterstitialAd()
{
if (interstitial.IsLoaded())
{
interstitial.Show();
}
}
private void RequestInterstitial()
{
#if UNITY_ANDROID
string adUnitId = "ca-app-pub-3940256099942544/1033173712";
#elif UNITY_IOS
string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
#else
string adUnitId = unexpected_platform";
#endif
interstitial = new InterstitialAd(adUnitId);
interstitial.OnAdClosed += Interstitial_OnAdClosed;
//AdRequest request = new AdRequest.Builder().Build();
AdRequest request = new AdRequest.Builder()
.AddTestDevice(AdRequest.TestDeviceSimulator)
.AddTestDevice(SystemInfo.deviceUniqueIdentifier)
.Build();
interstitial.LoadAd(request);
}
private void Interstitial_OnAdClosed(object sender, System.EventArgs e)
{
RequestInterstitial();
}
Answer by LilGames · Jan 31, 2019 at 08:03 PM
Update executes EVERY FRAME! You should not be calling the ad from Update() but from somewhere else that only triggers ONCE when it's game over. I leave that to you to figure out where in all your game's scripts it is best to put that.
waaaaaaaaaaaaa i did it show up only once at death time, sincerely i was mad when you answer like this but now i understand why you said like that, i learned something new, i put in the Game$$anonymous$$anager, to find the object type :). But how i solve the problem with the fact that it's showing up every death, and that can be annoying, should i put a count on death( i don't know how) or put like show up every TOT time ? but the time is not good with the death of the player that is a variable that depends from the player, like if someone is good can be playing more than 1 $$anonymous$$ute and so he will get back again a AD.
:) I am glad you realized why my answer was not just code for you to copy-paste. Not every game is set up the same way and I can't guess where your code that sets isGameOver is... Glad you got this far.
For your next problem, you have two choices:
A. Control the ad frequency in-game by adding a counter variable to your Interstitial class. or B. Control it externally through Ad$$anonymous$$ob ad campaign settings.
For A, add a counter variable to the class, such as:
private int adCounter = 4;
And in the showInterstitial class:
public void showInterstitialAd()
{
if (interstitial.IsLoaded())
{
if(--adCounter == 0){
adCounter = 4; // reset the counter
interstitial.Show();
}
}
}
I recommend #B, because it lets you change the ad frequency without ever publishing a new build and getting people to update their app. Ins$$anonymous$$d what you do is:
Go to your Admob account
Go to the App
Click on the App Unit you want to edit
Find the section called "Frequency Capping" and Enable it.
Set how often you want to allow the ad to be displayed.
Unfortunately this method doesn't set it to counter based, (like "every 3 calls") type of frequency and ins$$anonymous$$d it is time based (like "no more than once every 2 $$anonymous$$utes") but the benefit of "outside the app" control is a good thing to have.
You could actually still combine both methods.
Yeah i did with Admob, thank you so much. I have published it. Thanks again.
Your answer
Follow this Question
Related Questions
Admob script help 0 Answers
Admob interstitial ad not showing up 1 Answer
My admob interstitial ads only shows once 0 Answers
Interstitial Ads not display 0 Answers
Unity Ads AdMob Mediation Setup 0 Answers