K
K
Kirill2021-03-18 23:10:14
Unity
Kirill, 2021-03-18 23:10:14

What's wrong with admob?

In Unity, my code works, but on the phone, ads are not shown at all.
I have AdPlacement by AdMob installed (but I only use AdMob)

AdMob Settings
6053b270df21a784974671.png
App ID моего приложения указан.

My code
using UnityEngine;using GoogleMobileAds.Api;

public class GoogleMobileAdsDemoScript : MonoBehaviour
{
    
    private InterstitialAd interstitial;

    void Start()
    {
        MobileAds.Initialize(initStatus => { });
        RequestInterstitial();
        if (this.interstitial.IsLoaded())
        {
            this.interstitial.Show();
        }
    }
    private void RequestInterstitial()
    {
        #if UNITY_ANDROID
                string adUnitId = "ca-app-pub-3940256099942544/1033173712";
        #elif UNITY_IPHONE
                string adUnitId = "ca-app-pub-3940256099942544/4411468910";
        #else
                string adUnitId = "unexpected_platform";
        #endif
        if (interstitial !=null)
        {
            interstitial.Destroy();
        }
        this.interstitial = new InterstitialAd(adUnitId);
        AdRequest request = new AdRequest.Builder().Build();
        this.interstitial.LoadAd(request);
    }
}

Explain what is wrong, what are the options. I've been looking for how to embed ads for about a week now.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Black Basher, 2021-03-19
@kirilla39

I had such an error, most likely the ad has not yet had time to load. Both methods are called in Start, if possible, make the display on the button, and load it in Start () and in the Event (in my opinion it is called OnAdClosed, is in the documentation).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question