2017-02-23 66 views
0

我将此脚本附加到主按钮onclick并以统一方式运行,但它显示DUMMY SHOW INTERSTITIAL。当我在我的设备上部署时,会显示消息,“不幸的是,APP已停止”。
我尝试了很多次,只是做了一些小改动和一些重大更改,但每次都显示DUMMY INTERSTITIAL SHOW,但是在设备上运行我的应用程序时,它给出了错误SORRY, UNFORTUNATELY APP HAS STOPPED,这是我的主代码。任何人都可以检查这个,并告诉我是否有任何错误,或者我该怎么做才能运行这段代码。Unity5 admob插页式广告在设备中无法实现

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

public class AdMobController : MonoBehaviour { 

    InterstitialAd interstitial; 
    // Use this for initialization 
    void Start() {  
     //RequestBanner(); 
     RequestInterstitial(); 
    } 

    public void RequestInterstitial() 
    { 
     #if UNITY_ANDROID 
     string adUnitId = "AD_UNIT_ID"; 
     #elif UNITY_IPHONE 
     string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE"; 
     #else 
     string adUnitId = "unexpected_platform"; 
     #endif 

     // Initialize an InterstitialAd. 
     interstitial = new InterstitialAd(adUnitId); 
     // Create an empty ad request. 
     AdRequest request = new AdRequest.Builder().Build(); 
     // Load the interstitial with the request. 
     interstitial.LoadAd(request); 
     // Called when an ad request has successfully loaded. 
     interstitial.OnAdLoaded += HandleOnAdLoaded; 
     // Called when an ad request failed to load. 
     interstitial.OnAdFailedToLoad += HandleOnAdFailedToLoad; 
     // Called when an ad is clicked. 
    } 

    public void HandleOnAdLoaded(object sender, EventArgs args) 
    { 
     print("OnAdLoaded event received."); 
     // Handle the ad loaded event. 
    } 
    public void HandleOnAdFailedToLoad(object sender, AdFailedToLoadEventArgs args) 
    { 
     print("Interstitial Failed to load: " + args.Message); 
     // Handle the ad failed to load event. 
    } 
    public void ChangeScene (int sceneToChangeTo) { 
     Application.LoadLevel (sceneToChangeTo); 

      interstitial.Show(); 

    } 
} 

回答

0

我怀疑您错过了使用Admob所需的依赖关系。

转到资产- >播放服务解析器- >Android的解析器- >解决客户罐

这会将所有必需的依赖项导入到您的项目中。

+0

我做到了,但没有任何反应 –

0

首先只是调用

interstitial.Show

方法时,你已经检查插页式广告是否准备好展示。你可以使用admob api中的方法。 你也可以解释一下如何在启动方法中调用方法时如何在按钮上单击运行代码?

+0

我刚刚添加了这个脚本到我的按钮,并调用这个方法sceneChange从点击按钮督察, –

+0

好吧,问题在于你直接调用Start方法的方法,所以它剂量使如果你点击它不同,它会在类初始化时立即调用。你也许应该改变它,所以“interstitial.Show();”在切换场景之前调用 – Nino9612

相关问题