- Home /
Admob Interstitial ads are not showing up?
I want to show interstitial ads after 5 times of gameplay. I have written the below code and added it to a game object. So that when the user clicks the restart button 5 times (ie, after 5 gameplays) an interstitial ad should show up but its not. Banner ads are showing correctly but interstitial ads are not showing?
using System;
using UnityEngine;
using GoogleMobileAds;
using GoogleMobileAds.Api;
public class GoogleAdmob : MonoBehaviour {
private int count; private BannerView bannerView; private InterstitialAd interstitial;
void Start(){
count = PlayerPrefs.GetInt("Count");
RequestBanner ();
RequestInterstitial ();
bannerView.Show ();
if (count > 5) {
ShowInterstitial();
count = 0;
PlayerPrefs.SetInt ("Count", count);
}
count += 1;
PlayerPrefs.SetInt ("Count", count);
}
void Update(){
if(Input.GetKeyDown(KeyCode.Escape)){
bannerView.Destroy();
interstitial.Destroy();
Application.LoadLevel("MainMenu");
}
}
private void RequestBanner() {
#if UNITY_ANDROID
string adUnitId = "ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxxxxx";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
// Create a 320x50 banner at the top of the screen.
bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Bottom);
AdRequest request = new AdRequest.Builder().Build();
// Register for ad events.
bannerView.AdLoaded += HandleAdLoaded;
bannerView.AdFailedToLoad += HandleAdFailedToLoad;
bannerView.AdOpened += HandleAdOpened;
bannerView.AdClosing += HandleAdClosing;
bannerView.AdClosed += HandleAdClosed;
bannerView.AdLeftApplication += HandleAdLeftApplication;
// Load a banner ad.
bannerView.LoadAd(request);
}
private void RequestInterstitial() {
#if UNITY_ANDROID
string adUnitId = "ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxxxxx";
#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);
AdRequest request = new AdRequest.Builder().Build();
// 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(request);
}
// Returns an ad request with custom ad targeting.
private void ShowInterstitial() {
if (interstitial.IsLoaded()) {
interstitial.Show();
}
}
I have this same problem on Unity 5.1, Banner ads work fine, interstitial ads won't show... Trying various methods but nothing has worked so far.
Answer by Altered · Jun 14, 2015 at 01:45 PM
For me the problem seems to happen because the interstitial ad takes a while to load (sometimes up to 3 seconds). You're trying to call it too fast, and it's not loaded, so nothing happens. What I did was continually try to show the interstitial ad in void Update until it shows (using a bool called shown):
void Update () {
if (shown == false) {
ShowInterstitial();
Debug.Log ("Not yet...");
} }
public void ShowInterstitial()
{
if (interstitial.IsLoaded())
{
interstitial.Show();
shown = true;
} else {
Debug.Log ("Interstitial is not ready yet.");
} }
You could also load the ad at the beginning of the level, and then only call it when the round is over.
Is it good to show Interstitial ads continusly? Is it falls under Ad$$anonymous$$ob guidelines or not?
I too had the Same Problem with the Admob Interstitial Ads , Now it works prefectly. Thank You So so much. I will never Forget u in my life. Thanku thank u than...................................................................................... Thak u
Thank you Altered, you help for me. I wanna introduce a variant of your script.
When call show you can use StartCoroutine.It is better to wait and try every few milliseconds instead of every frame. This is to save compute, battery and CPU cycles
//When you want call Interstitial show
StartCoroutine(showInterstitial());
IEnumerator showInterstitial()
{
while(!this.interstitial.IsLoaded())
{
Debug.Log("Si sta aspettando che l'interstitial sia caricato");
yield return new WaitForSeconds(0.2f);
}
this.interstitial.Show();
}
StartCoroutine(showInterstitial());
IEnumerator showInterstitial()
{`
while(!this.interstitial.IsLoaded())
{
Debug.Log("Si sta aspettando che l'interstitial sia caricato");
yield return new WaitForSeconds(0.2f);
}
this.interstitial.Show();
}
Answer by isrmicha · Jun 14, 2015 at 07:22 AM
are you using the right ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxxxxx for instertitial ? you create a full ad for your app in admob ?
Answer by bigjobs · Feb 28, 2016 at 02:24 PM
download this last plugin https://github.com/unity-plugins/Unity-Admob and then add code
4.How to integrate Interstitial into Unity 3d app?
Here is the minimal banner code to create an interstitial.
Admob.Instance().loadInterstitial();
Unlike banners, interstitials need to be explicitly shown. At an appropriate stopping point in your app, check that the interstitail is ready before showing it:
if (Admob.Instance().isInterstitialReady()) {
Admob.Instance().showInterstitial();
}
Your answer
Follow this Question
Related Questions
How to debug Android apps that use Admob 1 Answer
quit game if no internet access on android 1 Answer
Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define 0 Answers
My game crahses when I use it on a phone 0 Answers
Update the Android Gallery after take a screenshot from android device using unity3d 1 Answer