現在作成しているandoroidゲームアプリにAdmobのバナー広告を追加しようとしています。
ゲームのメインシーンでは表示させず、リザルトシーンでのみ表示するようにしたいのですが、うまくいきません。
using UnityEngine;
using System.Collections;
using GoogleMobileAds.Api;
public class AdMobManager : MonoBehaviour {
public string Android_Banner;
public string ios_Banner;
public static BannerView bannerView; public static InterstitialAd interstitial; private AdRequest request; // Use this for initialization void Awake () { RequestBanner (); } public void RequestBanner() { #if UNITY_ANDROID string adUnitId = Android_Banner; #elif UNITY_IPHONE string adUnitId = ios_Banner; #else string adUnitId = "unexpected_platform"; #endif // Create a 320x50 banner at the top of the screen. bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Top); // Create an empty ad request. request = new AdRequest.Builder() .AddTestDevice(AdRequest.TestDeviceSimulator) // Simulator. .AddTestDevice("xxxxxxxxxxxxxx") // My test Device. .Build(); // Load the banner with the request. bannerView.LoadAd(request); }
}
上記のコードを記入したスクリプトを作り、空のゲームオブジェクトにつけて、
using UnityEngine;
using System.Collections;
using GoogleMobileAds;
using GoogleMobileAds.Api;
public class admobBanner : MonoBehaviour {
private static BannerView bannerView; public static void bannerLoad() { if (bannerView == null) { bannerView = new BannerView ("広告ID", AdSize.Banner, AdPosition.Bottom); AdRequest request = new AdRequest.Builder ().Build (); //bannerView.LoadAd (request); } } public static void bannerShow() { if (bannerView != null) { bannerView.Show (); } } public static void bannerHide() { if (bannerView != null) { bannerView.Hide (); } }
}
もう一つ上記のスクリプトを作り、同じオブジェクトにつけて、シーン移動の直前で
admobBanner.bannerHide ();
と追記してみたのですがバナーが非表示になりませんでした。
どうしたら良いのか色々調べたのですがわかりません、どうかよろしくおねがいします。
あなたの回答
tips
プレビュー