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遊戲。
另外我在想,這是否可能是廣告需要一些額外的時間來加載,我再次點擊再試一次。但那麼解決方案會是什麼?
第一:不要發佈您的廣告單元ID - 它不安全。我alreade刪除它。第二:你等了嗎?有時,第一個廣告加載需要時間 –
我等了大約2-3秒。 –
把Debug.Log放在'if(interstitial.IsLoaded())'裏面,看看是否是真的。 – Programmer