无法在Unity中显示Admob广告开发构建

时间:2017-10-24 10:56:36

标签: unity3d build google-admob

我想征求意见。我能够在我的模拟器和真实设备中看到admob广告,如果在我的构建设置中检查了开发构建。

enter image description here

但如果没有,根本就没有广告。 即使检查了开发版本,是否可以构建一个即将在Google Play商店中发布的APK? 对不起,我是Unity的新手。

守则:

using UnityEngine;

使用System.Collections;  使用GoogleMobileAds.Api;

公共类AdScript:MonoBehaviour  {

 bool isShown;
 InterstitialAd interstitial;

 void Start()
 {

     RequestInterstitialAds();
 }

 void Update()
 {
     if (GameControl.isGameOver)
     {
         if (!isShown)
         {
             isShown = true;
             showInterstitialAd();
         }
     }
 }

 public void showInterstitialAd()
 {

     if (interstitial.IsLoaded())
     {
         interstitial.Show();

     }

 }


 private void RequestInterstitialAds()
 {
     //Testing
     string adID = "ca-app-pub-3940256099942544/1033173712";

     //Live
     //string adID = "MY ADD ID";                     

     #if UNITY_ANDROID
     string adUnitId = adID;
     #elif UNITY_IOS
     string adUnitId = adID;
     #else
     string adUnitId = adID;
     #endif

     // Initialize an InterstitialAd.
     interstitial = new InterstitialAd(adUnitId);

     //Test
     AdRequest request = new AdRequest.Builder()
     .AddTestDevice(AdRequest.TestDeviceSimulator)       // Simulator.
     .AddTestDevice("89D1DA1F820CE28BA86223A1C34****")  // My test device.
     .Build();

     //Production
     //AdRequest request = new AdRequest.Builder().Build();

     //Register Ad Close Event
     interstitial.OnAdClosed += Interstitial_OnAdClosed;

     //Load the interstitial with the request.
     interstitial.LoadAd(request);

     //Debug.Log("AD LOADED XXX");

 }


 private void Interstitial_OnAdClosed(object sender, System.EventArgs e)
 {
 //Resume Play Sound
 }

}

提前致谢。

1 个答案:

答案 0 :(得分:0)

您在顶部忘记了这个

MobileAds.initialize(appID);