Ads not showing on Game Unity

Viewed 2300

I have used the following code to put banner ads on my unity game but my ads are not showing neither the test ads nor the actual admob ads.I have no idea of whats going on i have completed my payment details in admob as well.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;

public class AdmobScript : MonoBehaviour 
{
     public string BannerId;

     void Start()
     {

        RequestBanner();


     }


     private void RequestBanner()
     {
     #if UNITY_EDITOR
     string adUnitId = "unused";

     #elif UNITY_ANDROID
         string adUnitId = BannerId;
     #elif UNITY_IPHONE
         string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
     #else
         string adUnitId = "unexpected_platform";
     #endif

         // Create a 320x50 banner at the bottom of the screen.
         BannerView bannerView = new BannerView(adUnitId, AdSize.Banner, 
         AdPosition.Bottom);
         // Create an empty ad request.
         AdRequest request = new AdRequest.Builder().Build();
         // Load the banner with the request.
         bannerView.LoadAd(request);
     }
 }

1 Answers

There's a missing function from your codes that will handle the show functionality of the bannerView object:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;

public class AdmobScript : MonoBehaviour 
{
     BannerView bannerView;

 void Start()
 {

    RequestBanner();
 }


 private void RequestBanner()
 {
 #if UNITY_EDITOR
 string adUnitId = "unused";

 #elif UNITY_ANDROID
     string adUnitId = BannerId;
 #elif UNITY_IPHONE
     string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
 #else
     string adUnitId = "unexpected_platform";
 #endif

     // Create a 320x50 banner at the bottom of the screen.
     BannerView bannerView = new BannerView(adUnitId, AdSize.Banner, 
     AdPosition.Bottom);
     // Create an empty ad request.
     AdRequest request = new AdRequest.Builder().Build();
     // Load the banner with the request.
     bannerView.LoadAd(request);
     // Handle the show functionality of banner ads
     bannerView.OnAdLoaded+=HandleOnAdLoaded;
 }

 void HandleOnAdLoadeded(object a, EventArgs args) {
     print("loaded");
     bannerView.Show();
 }

}

For more infos:

Related