1
votes

The Test Ads are working correctly but when I published it on play store, the ads were not working. Link to the game https://play.google.com/store/apps/details?id=com.GreyMacleno.FruitChop. Here is the Code of my AdManager

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using GoogleMobileAds.Api;

public class AdManager : MonoBehaviour
{
    public static AdManager Instance{get;set;}
    private BannerView bannerAd;
    private InterstitialAd interstitialAd;
    private RewardBasedVideoAd rewardVideoAd;




    void Awake()
    {
        if (Instance == null)
        {
            DontDestroyOnLoad(this.gameObject);
            Instance = this;
        }
        else if (Instance != this)
        {
            Destroy(this.gameObject);
            return;
        }
    }

    void Start()
    {
        MobileAds.Initialize(initStatus => { });
        RequestBanner();
        RequestInterstitial();

    }

    void RequestBanner(){

        // for real
        string banner_ID = "not showing but correctly entered";

        // for testing
        // string banner_ID = "ca-app-pub-3940256099942544/6300978111";

        bannerAd = new BannerView(banner_ID, AdSize.Banner, AdPosition.Bottom);

        // for real
        AdRequest adRequest = new AdRequest.Builder().Build();

        // For testing
        // AdRequest adRequest = new AdRequest.Builder().AddTestDevice("2077ef9a63d2b398840261c8221a0c9b").Build();

        bannerAd.LoadAd(adRequest);

    }

    void RequestInterstitial(){

        if(interstitialAd != null)
            interstitialAd.Destroy();

        // for real
        string interstitial_ID = "not showing but correctly entered";

        // for testing
        // string interstitial_ID = "ca-app-pub-3940256099942544/1033173712";
        interstitialAd = new InterstitialAd(interstitial_ID);

        // Called when an ad request has successfully loaded.
        interstitialAd.OnAdLoaded += HandleOnAdLoaded;

        // for real
        AdRequest adRequest = new AdRequest.Builder().Build();

        // For testing
        // AdRequest adRequest = new AdRequest.Builder().AddTestDevice("2077ef9a63d2b398840261c8221a0c9b").Build();

        interstitialAd.LoadAd(adRequest);
    }


    public void DisplayBanner(){
        bannerAd.Show();
    }

    public void DisplayInterstitialAd(){
        if(interstitialAd.IsLoaded()){
            interstitialAd.Show();
        }
        else{
            RequestInterstitial();
            interstitialAd.Show();
        }
    }


    public void HandleOnAdLoaded(object sender, EventArgs args)
    {
        DisplayBanner(); 
    }

    public void HandleOnAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
    {
        RequestBanner();
    }

    public void HandleOnAdOpened(object sender, EventArgs args)
    {
        MonoBehaviour.print("HandleAdOpened event received");
    }

    public void HandleOnAdClosed(object sender, EventArgs args)
    {
        MonoBehaviour.print("HandleAdClosed event received");    
    }

    public void HandleOnAdLeavingApplication(object sender, EventArgs args)
    {
        MonoBehaviour.print("HandleAdLeavingApplication event received");
    }

    void HandleBannerADEvents(bool subscribe){
        if(subscribe){
            // Called when an ad request has successfully loaded.
            this.bannerAd.OnAdLoaded += this.HandleOnAdLoaded;
            // Called when an ad request failed to load.
            this.bannerAd.OnAdFailedToLoad += this.HandleOnAdFailedToLoad;
            // Called when an ad is clicked.
            this.bannerAd.OnAdOpening += this.HandleOnAdOpened;
            // Called when the user returned from the app after an ad click.
            this.bannerAd.OnAdClosed += this.HandleOnAdClosed;
            // Called when the ad click caused the user to leave the application.
            this.bannerAd.OnAdLeavingApplication += this.HandleOnAdLeavingApplication;
        }
        else{
            // Called when an ad request has successfully loaded.
            this.bannerAd.OnAdLoaded -= this.HandleOnAdLoaded;
            // Called when an ad request failed to load.
            this.bannerAd.OnAdFailedToLoad -= this.HandleOnAdFailedToLoad;
            // Called when an ad is clicked.
            this.bannerAd.OnAdOpening -= this.HandleOnAdOpened;
            // Called when the user returned from the app after an ad click.
            this.bannerAd.OnAdClosed -= this.HandleOnAdClosed;
            // Called when the ad click caused the user to leave the application.
            this.bannerAd.OnAdLeavingApplication -= this.HandleOnAdLeavingApplication;
        }
    }
    void OnEnable(){
        HandleBannerADEvents(true);
    }

    void OnDisable(){
        HandleBannerADEvents(false);
    }
}

I am calling the DisplayInterstitialAd() where I want to run the interstitial Ads. Few are saying that I should wait, but its been 3 days and I am still waiting for the ads to show up. I have linked the app with Admob. The version of Unity is 2019.3.13f1.

1

1 Answers

0
votes

Found the solution. My Admob account was not verified and hence my ad serving was not enabled. Once it got verified the ads started showing up.