Abdu Omar
Abdu Omar

Reputation: 35

Why won't admob interstitial ads display?

So I've added banner and interstitial ads both from admob in my unity android project.So I've tested it on my test device and my banner ad is showing fine but my interstitial ad won't display.

I've made it on every 11 games to show the interstitial ad:

public void OnCollisionEnter2D(Collision2D other)
    {

        if (other.gameObject.tag == "Pipe")
        {
            s.GameOver();
            targetVelocity.y = 0;
            targetVelocity.x = 0;
            cube.gameObject.SetActive(false);
            score.gameObject.SetActive(false);
            this.anime2.enabled = true;

        }


        PlayerPrefs.SetInt("Ad Counter", PlayerPrefs.GetInt("Ad Counter") + 1);

        if (PlayerPrefs.GetInt("Ad Counter") > 10)
        {
            if (interstitial.IsLoaded())
            {
                interstitial.Show();
            }

            PlayerPrefs.SetInt("Ad Counter", 0);
        }
    }

And this is my request code:

private void RequestInterstitial()

    {
#if UNITY_ANDROID

        string adUnitId ="ca-app -pub-3960055046097211/6145173288";

#elif UNITY_IPHONE

        string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";

#else

        string adUnitId = "unexpected_platform";

#endif

        // Initialize an InterstitialAd.

        InterstitialAd interstitial = new InterstitialAd(adUnitId);

        // Create an empty ad request.

        AdRequest request = new AdRequest.Builder().Build();

        // Load the interstitial with the request.

        interstitial.LoadAd(request);
    }

Of course afterwards i called the method in the start().

So where is the problem?Should i put this script on an empty object?

Upvotes: 1

Views: 1573

Answers (2)

temoor wali
temoor wali

Reputation: 11

Add permission as mentioned above and call interstitial in update because it takes a while to load. Thanks

enter code here

InterstitialAd interstitial;
bool check;

private void RequestInterstitial()
{

     interstitial = new InterstitialAd(adUnitId);
    AdRequest request = new AdRequest.Builder().Build();
    interstitial.LoadAd(request);

}
void Update()
{
    if (!check) {
        if (interstitial.IsLoaded ()) {
            interstitial.Show ();
            check = true;
        }
    }
}
enter code here

Upvotes: 1

George Rappel
George Rappel

Reputation: 7188

If you want to use Interstitial Ads you need to add some permissions on your Manifest file.

An Ad Activity that will hold the Ads. Only one is required for the whole project and request permission to use internet to load the ads (if you're not already requiring them for other stuff):

<manifest ...>

  <!-- Include required permissions for Google Mobile Ads to run-->
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

  <application>

     //...

     <!--Include the AdActivity configChanges and theme. -->
     <activity android:name="com.google.android.gms.ads.AdActivity"
      android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
      android:theme="@android:style/Theme.Translucent" />
  </application>
</manifest>

Source.

Upvotes: 0

Related Questions