首页 文章

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

提问于
浏览
0

我想征求意见 . 我能够在我的模拟器和真实设备中看到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

    你在顶部忘了这个

    MobileAds.initialize(appID);
    

相关问题