2016-12-28 87 views
0

我试图在用户播放每5场比赛后插入一个插页式广告。我所做的是用下面的脚本创建一个空对象:插页式广告不显示admob插件的团结

using UnityEngine; 
using GoogleMobileAds.Api; 

public class AdBetweenGames : MonoBehaviour { 
    InterstitialAd interstitial; 

    void Start() 
    { 
     if(PlayerPrefs.GetInt("games-played", -1) % 5 == 0) 
     { 
      this.ShowInterstitial(); 
     } 
    } 

    private void RequestInterstitial() 
    { 
     string adUnitId = "UNITID"; 


     // 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); 
    } 

    public void ShowInterstitial() 
    {  
     RequestInterstitial(); 
     Debug.Log("Interstatial ad called."); 
     if (interstitial.IsLoaded()) 
     { 
      interstitial.Show(); 
     } 
    } 
} 

我确定这里的代码是根据调试日志正确调用的。我也尝试过横幅广告,并在1-2秒后显示没有问题。我正在制作一款Android游戏。

另外我在想,这是否可能是广告需要一些额外的时间来加载,我再次点击再试一次。但那么解决方案会是什么?

+0

第一:不要发布您的广告单元ID - 它不安全。我alreade删除它。第二:你等了吗?有时,第一个广告加载需要时间 –

+0

我等了大约2-3秒。 –

+0

把Debug.Log放在'if(interstitial.IsLoaded())'里面,看看是否是真的。 – Programmer

回答

0

广告暴徒的插页广告需要时间来加载尝试在更新,并等待至少4秒,并呼吁ShowInterstitial函数内部bool设置其起始值truefalse它调用函数一次展示广告后。

相关问题