Search code examples
c#unity-game-engineadmob

using admob banners in unity


I'm using the following code to implement a banner ad at the bottom on my game screen in unity.

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

public class AdScript : MonoBehaviour {   

    // Use this for initialization
    void Start () {    

        showBannerAd();    

    }

    private void showBannerAd()     
    {
        string adID = "ca-app-pub-***********";    

        //***For Testing in the Device***
        AdRequest request = new AdRequest.Builder()    
            .AddTestDevice(AdRequest.TestDeviceSimulator)           // Simulator.
            .AddTestDevice("***********")  // My test device.
            .Build();    

        //***For Production When Submit App***
        //AdRequest request = new AdRequest.Builder().Build();    

        BannerView bannerAd = new BannerView(adID, AdSize.SmartBanner, AdPosition.Bottom);    
        bannerAd.LoadAd(request);    
    }

    // Update is called once per frame
    void Update () {    

    }    
}

When I run it I get a notification on the log of:

Dummy .ctor Dummy Createbannerview Dummy LoadAd

but not a mock pop up banner saying "a banner ad will be implemented here"

Will the ads be implemented when published or did I misunderstand a step in the tutorial?


Solution

  • Admob banners will only be displayed when building to ios or Android and running it on a target device. You will never see a banner in the unity editor. It does not matter if you run test ads or not, they just won't show in the editor.