Unity ads is showing in editor but not in real android phone in Unity Version

34 Views Asked by At

I am trying to add Unity ads in my game for Android (Unity Version 2022.3.14f). Ads are working in the editor but when I create a build and run it in my phone ads are not showing.

AdsManager.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class AdsManager : MonoBehaviour
{
    public InitalizeAd initalizeAd;
    public InterstitialAds interstitialAds;
    public RewaredAds rewaredAds;
    public BannerAds bannerAds;

    public static AdsManager Instance {get;private set;}

    private void Awake() {
        if (Instance !=null && Instance !=this)
        {
            Destroy(gameObject);
            return;
        }

        Instance = this;
        DontDestroyOnLoad(gameObject);

        bannerAds.LoadBannerAds();
        interstitialAds.LoadInterstitialAds();
        rewaredAds.LoadRewaredAds();
    }
}

Banner.cs

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;
public class BannerAds : MonoBehaviour
{
    [SerializeField]
    private string androidAdUnitId;
    [SerializeField]
    private string iosAdUnitId;

    private string adUnitId;

    private void Awake() {
        #if UNITY_IOS
                adUnitId =iosAdUnitId;
        #elif UNITY_ANDROID
                adUnitId = androidAdUnitId;
        #endif

        Advertisement.Banner.SetPosition(BannerPosition.BOTTOM_CENTER);


    }

    public void LoadBannerAds(){
        BannerLoadOptions options = new BannerLoadOptions
        {
            loadCallback = BannerLoaded,
            errorCallback = BannerLoadedError
        };

        Advertisement.Banner.Load(adUnitId,options);
    }

    public void ShowBannerAd(){
        BannerOptions options = new BannerOptions
        {
            showCallback = BannerShown,
            clickCallback = BannerClicked,
            hideCallback = BannerHidden
        };

        Advertisement.Banner.Show(adUnitId,options);
    }

    public void HideBannerAd(){
        Advertisement.Banner.Hide();
    }

    private void BannerHidden()
    {
        throw new NotImplementedException();
    }

    private void BannerClicked()
    {
        throw new NotImplementedException();
    }

    private void BannerShown()
    {
        Debug.Log("Banner is showned");
    }

    private void BannerLoadedError(string message)
    {
        throw new NotImplementedException();
    }

    private void BannerLoaded()
    {
        throw new NotImplementedException();
    }
}

When I run the game in the editor I get some error like:

placementId cannot be nil or empty
UnityEngine.Advertisements.Advertisement:Load (string,UnityEngine.Advertisements.IUnityAdsLoadListener)

and

NotImplementedException: The method or operation is not implemented.

only once when I start. Can any one please help me?

0

There are 0 best solutions below