3

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);
     }
 }

sakiM
  • 4,832
  • 5
  • 27
  • 33
Aqsa Nadeem
  • 87
  • 1
  • 8

1 Answers1

4

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:

Jessica Rodriguez
  • 2,899
  • 1
  • 12
  • 27
  • Yes they don't seen to help , problem is still there – Aqsa Nadeem Sep 17 '18 at 09:45
  • Check - > https://www.youtube.com/playlist?list=PLgAF6rpCsTCic6RXiXsHJwydha0Xvm7eY Unity 3d Google Play Services Integration 2018 tutorials: 1. How to Upload game on play store and integrate google play services. 2. How to login user in google play in unity. 3. How to add leaderboard in unity game. 4. how to add acheivements in your game in unity 2018. 5. how to integrate google admob banner and interstitial ads in unity. 6. google play services multiplayer integration. 7. saving game data on google cloud. – Jessica Rodriguez Sep 17 '18 at 10:01