Hi, I’m trying to setup Admob banner on my game. Interstitials work fine, but I don’t know why my normal banners don’t show.
I can even see the Dummy ShowBannerView on the console.
Dummy ShowBannerView
UnityEngine.Debug:Log(Object)
GoogleMobileAds.Common.DummyClient:ShowBannerView() (at Assets/GoogleMobileAds/Common/DummyClient.cs:25)
GoogleMobileAds.Api.BannerView:Show() (at Assets/GoogleMobileAds/Api/BannerView.cs:40)
GoogleAdsController:ShowBanner() (at Assets/Scripts/Utils/GoogleAdsController.cs:61)
AdsShow:Start() (at Assets/Scripts/Ads/AdsShow.cs:20)
This is my GoogleAdsController.cs
using System;
using UnityEngine;
using System.Collections;
// Google ads
using GoogleMobileAds;
using GoogleMobileAds.Api;
public class GoogleAdsController : MonoBehaviour
{
public static GoogleAdsController instance = null;
private BannerView bannerView;
private InterstitialAd interstitial;
// Use this for initialization
void Awake()
{
if (instance == null)
{
instance = this;
}
else if (instance != null)
{
Destroy(gameObject);
}
DontDestroyOnLoad(gameObject);
}
public void RequestBanner()
{
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "MY AD UNIT ID edited for this post";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
// Create a banner.
bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Top);
// 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(createAdRequest());
}
public void ShowBanner()
{
bannerView.Show();
Debug.Log ("Showing Google Banner Top");
}
public void HideBanner()
{
bannerView.Hide();
}
public void RequestInterstitial()
{
// http://stackoverflow.com/questions/12553929/is-there-any-admob-dummy-id
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "MY AD UNIT ID edited for this post";
#elif UNITY_IPHONE
string adUnitId = "";
#else
string adUnitId = "unexpected_platform";
#endif
// Create an interstitial.
interstitial = new InterstitialAd(adUnitId);
// 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(createAdRequest());
}
// Returns an ad request with custom ad targeting.
private AdRequest createAdRequest()
{
return new AdRequest.Builder()
#if UNITY_EDITOR
.AddTestDevice(AdRequest.TestDeviceSimulator)
#else
//.AddTestDevice(AdRequest.TestDeviceSimulator)
//.AddTestDevice("XXXXXXXXXXXXXXXXXXXXX")
//.AddKeyword("game")
//.SetGender(Gender.Male)
//.SetBirthday(new DateTime(1985, 1, 1))
//.TagForChildDirectedTreatment(false)
//.AddExtra("color_bg", "9B30FF")
#endif
.Build();
}
public void ShowInterstitial()
{
if (interstitial.IsLoaded())
{
interstitial.Show();
}
else
{
//print("Google Ads: Interstitial is not ready yet.");
}
RequestInterstitial();
}
#region Banner callback handlers
public void HandleAdLoaded(object sender, EventArgs args)
{
//print("Google Ads: HandleAdLoaded event received.");
}
public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
//print("Google Ads: HandleFailedToReceiveAd event received with message: " + args.Message);
}
public void HandleAdOpened(object sender, EventArgs args)
{
//print("Google Ads: HandleAdOpened event received");
}
void HandleAdClosing(object sender, EventArgs args)
{
//print("Google Ads: HandleAdClosing event received");
}
public void HandleAdClosed(object sender, EventArgs args)
{
//print("Google Ads: HandleAdClosed event received");
}
public void HandleAdLeftApplication(object sender, EventArgs args)
{
//print("Google Ads: HandleAdLeftApplication event received");
}
#endregion
#region Interstitial callback handlers
public void HandleInterstitialLoaded(object sender, EventArgs args)
{
//print("Google Ads: HandleInterstitialLoaded event received.");
}
public void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
//print("Google Ads: HandleInterstitialFailedToLoad event received with message: " + args.Message);
}
public void HandleInterstitialOpened(object sender, EventArgs args)
{
//print("Google Ads: HandleInterstitialOpened event received");
}
void HandleInterstitialClosing(object sender, EventArgs args)
{
//print("Google Ads: HandleInterstitialClosing event received");
}
public void HandleInterstitialClosed(object sender, EventArgs args)
{
//print("Google Ads: HandleInterstitialClosed event received");
}
public void HandleInterstitialLeftApplication(object sender, EventArgs args)
{
//print("Google Ads: HandleInterstitialLeftApplication event received");
}
#endregion
}
And AdsShow.cs on MainCamera
using UnityEngine;
using System.Collections;
public class AdsShow : MonoBehaviour {
public bool GoogleBannerActive = true;
void Awake (){
}
// Use this for initialization
void Start () {
//Checks if ads active
if (GoogleBannerActive) {
GoogleAdsController.instance.RequestBanner();
GoogleAdsController.instance.ShowBanner ();
Debug.Log ("Calling Google Banner Top");
}
}
// Update is called once per frame
void Update () {
}
Any help would be appreciated!