2017-08-26 84 views
0

這是我的代碼,我會在幾秒鐘後顯示它,不僅在Gameover中,我的應用程序中沒有gameover功能。我會盡可能地展示插頁式廣告。我會在幾秒鐘後做admob顯示...如何

我的代碼已關閉,如果我啓動應用程序並快速點擊音板,則不會顯示插頁式廣告。

using GoogleMobileAds.Api; 
using UnityEngine; 

public class GameScript : MonoBehaviour { 
bool hasShownAdOneTime; 

// Use this for initialization 
void Start() 
{ 
    //Request Ad 
    RequestInterstitialAds(); 
} 

void Update() 
{ 
    //if (GameScript.isGameOver) 
    { 
     if (!hasShownAdOneTime) 
     { 
      hasShownAdOneTime = true; 
      Invoke("showInterstitialAd", 2.0f); 
     } 
    } 
} 

public void showInterstitialAd() 
{ 
    //Show Ad 
    if (interstitial.IsLoaded()) 
    { 
     interstitial.Show(); 

     //Stop Sound 
     // 

     Debug.Log("SHOW AD XXX"); 
    } 

} 

InterstitialAd interstitial; 
private void RequestInterstitialAds() 
{ 
    string adID = ""; 

    #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("2077ef9a63d2b398840261c8221a0c9b") // 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"); 

    } 

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

    } 

回答

0

加載廣告需要一些時間(視頻廣告需要10-60秒)。所以,如果你顯示得太早,它不會加載。確保interstitial.IsLoaded()返回true。