简体   繁体   中英

Interstitial Ads not showing admob plugin for unity

I am trying to put an interstitial ad after every 5 games the user plays. What I've done is created an empty object with the following script:

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

I am sure the code here is called properly based on the debug log. I've also tried doing banner ads and they show without a problem after 1-2 seconds. I am making an android game.

Also I was thinking, could it be that the ad needs some extra time to load and I am clicking try again too early. But then what would a solution be?

ad mob的非页内广告需要时间来加载,以便在更新中尝试并等待至少4秒钟, ShowInterstitialbool调用ShowInterstitial函数,并在开始时将其值设置为true ,然后在调用一次展示广告的函数后将其设置为false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM