I give up and ask here.
I’ve been struggleing with this for days now. Admob plugin works just fine. Banner shows as it should and Interstitial as well … but only once.
I realize that the interstitial needs to be destroyed manually (and I assume created/loaded again after that), but just can’t get it to work.
here’s the basic code I use.
private InterstitialAd interstitial;
int admobNumber;
void Start()
{
DontDestroyOnLoad(this);
RequestInterstitial ();
}
void Update()
{
admobNumber = PlayerPrefs.GetInt("AdmobInt")%10;
if (admobNumber == 5) {
ShowInterstitial();
Debug.Log("showing interstitial");
PlayerPrefs.SetInt("AdmobInt",PlayerPrefs.GetInt("AdmobInt")+1);
Debug.Log(PlayerPrefs.GetInt("AdmobInt"));
}
/*if (admobNumber == 9) {
interstitial.Destroy();
//RequestInterstitial ();
} */
}
private void RequestInterstitial()
{
#if UNITY_EDITOR
string adUnitId = "unused2";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-XXXXXXXXXXXXX";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
// Create an interstitial.
interstitial = new InterstitialAd(adUnitId);
// Register for ad events.
interstitial.AdLoaded += HandleInterstitialLoaded;
interstitial.AdFailedToLoad += HandleInterstitialFailedToLoad;
interstitial.AdOpened += HandleInterstitialOpened;
interstitial.AdClosing += HandleInterstitialClosing;
interstitial.AdClosed += HandleInterstitialClosed;
interstitial.AdLeftApplication += HandleInterstitialLeftApplication;
// Load an interstitial ad.
interstitial.LoadAd(createAdRequest());
}
// Returns an ad request with custom ad targeting.
private AdRequest createAdRequest()
{
return new AdRequest.Builder()
.AddTestDevice(AdRequest.TestDeviceSimulator)
.AddTestDevice("9ACD01B470951161A30C0AA4B6DA3A7D")
.AddKeyword("game")
.SetGender(Gender.Male)
.SetBirthday(new DateTime(1982, 1, 1))
.TagForChildDirectedTreatment(false)
.AddExtra("color_bg", "9B30FF")
.Build();
}
private void ShowInterstitial()
{
if (interstitial.IsLoaded())
{
interstitial.Show();
}
else
{
print("Interstitial is not ready yet.");
}
removing the DontDestroyOnLoad and adding the script manually to each/some scene doesn’t change the behaviour. Tried interstitial.Destroy() at different places. Console tells me it gets destroyed but it looks like it never gets created again.
I’m completely lost, any input is welcome (please don’t suggest plugins)