2017-02-23 43 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