Search Unity

Bug unity ads not working

Discussion in 'Editor & General Support' started by Mohammed199, Jan 15, 2023.

  1. Mohammed199

    Mohammed199

    Joined:
    Feb 19, 2021
    Posts:
    1
    Hello I have a project that I bought from the unity asset store It has admob and unity ads And when running unity ads and following step by step game developer instructions And the test ad experience is not working, I don't know why Game https://assetstore.unity.com/packages/templates/systems/pop-blocks-puzzle-game-kit-188953?


    ADmanger SCRIPT:

    using UnityEngine;
    using System;
    using UnityEngine.Advertisements;
    using System.Collections;
    using UnityEngine.Events;
    public class ADManager : MonoBehaviour, IUnityAdsInitializationListener, IUnityAdsShowListener, IUnityAdsLoadListener
    {
    private static ADManager _instance;
    UnityAction callback;
    public string gameID, bannerPlacement, interstitialPlacement, rewardedVideoPlacement;
    public bool TestADS = false;
    bool isRewardedLoaded;
    public static ADManager Instance
    {
    get
    {
    if (_instance == null)
    {
    _instance = GameObject.FindObjectOfType<ADManager>();
    DontDestroyOnLoad(_instance.gameObject);
    }
    return _instance;
    }
    }
    void Awake ()
    {
    if (_instance == null)
    {
    _instance = this;
    DontDestroyOnLoad(this);
    }
    else
    {
    if (this != _instance)
    Destroy(this.gameObject);
    }
    }
    private void Start ()
    {
    //yield return new WaitForEndOfFrame();
    Invoke("InIt", 3);
    }
    void LoadAds ()
    {
    LoadInterstitial();
    LoadRewarded();
    }
    void InIt ()
    {
    Advertisement.Initialize(gameID, TestADS, this);
    }
    public void LoadBanner ()
    {
    BannerLoadOptions options = new BannerLoadOptions
    {
    loadCallback = OnBannerLoaded,
    errorCallback = OnBannerError
    };
    Advertisement.Banner.SetPosition(BannerPosition.BOTTOM_CENTER);
    Advertisement.Banner.Load(bannerPlacement, options);
    }
    void OnBannerLoaded ()
    {
    ShowBannerAd();
    }
    // Implement code to execute when the load errorCallback event triggers:
    void OnBannerError (string message)
    {
    Debug.Log($"Banner Error: {message}");
    Invoke("LoadBanner", 3);
    }
    // Implement a method to call when the Show Banner button is clicked:
    void ShowBannerAd ()
    {
    // Set up options to notify the SDK of show events:
    BannerOptions options = new BannerOptions
    {
    clickCallback = OnBannerClicked,
    hideCallback = OnBannerHidden,
    showCallback = OnBannerShown
    };
    Advertisement.Banner.Show(bannerPlacement, options);
    }
    // Implement a method to call when the Hide Banner button is clicked:
    void HideBannerAd ()
    {
    Advertisement.Banner.Hide();
    }
    void OnBannerClicked () { }
    void OnBannerShown () { }
    void OnBannerHidden () { }
    public void LoadInterstitial ()
    {
    Advertisement.Load(interstitialPlacement, this);
    }
    // Show the loaded content in the Ad Unit:
    public void ShowInterstitialAd ()
    {
    Advertisement.Show(interstitialPlacement,this);
    }
    public void LoadRewarded ()
    {
    Advertisement.Load(rewardedVideoPlacement, this);
    }
    public bool isRewardedVideoLoaded ()
    {
    return isRewardedLoaded;
    }
    public void ShowRewardedVideo (UnityAction tempcallback)
    {
    callback = tempcallback;
    Advertisement.Show(rewardedVideoPlacement, this);
    }

    public void OnUnityAdsDidError (string message)
    {
    Advertisement.Load(interstitialPlacement);
    Advertisement.Load(rewardedVideoPlacement);
    }
    public void OnInitializationComplete ()
    {
    Invoke("LoadAds", 3);
    }
    public void OnInitializationFailed (UnityAdsInitializationError error, string message)
    {
    }
    public void OnUnityAdsShowFailure (string placementId, UnityAdsShowError error, string message)
    {
    Advertisement.Load(placementId,this);
    }
    public void OnUnityAdsShowStart (string placementId)
    {
    }
    public void OnUnityAdsShowClick (string placementId)
    {
    }
    public void OnUnityAdsShowComplete (string placementId, UnityAdsShowCompletionState showCompletionState)
    {
    print(placementId + "-----------------------------");
    if (rewardedVideoPlacement.Equals(placementId))
    {
    if (showCompletionState == UnityAdsShowCompletionState.COMPLETED)
    {
    callback.Invoke();
    // Reward the user for watching the ad to completion.
    }
    else if (showCompletionState == UnityAdsShowCompletionState.SKIPPED)
    {
    LoadRewarded();
    // Do not reward the user for skipping the ad.
    }
    else if (showCompletionState == UnityAdsShowCompletionState.UNKNOWN)
    {
    LoadRewarded();
    Debug.LogWarning("The ad did not finish due to an error.");
    }
    }
    Advertisement.Load(placementId);
    }
    public void OnUnityAdsAdLoaded (string placementId)
    {
    if (placementId == rewardedVideoPlacement)
    isRewardedLoaded = true;
    }
    public void OnUnityAdsFailedToLoad (string placementId, UnityAdsLoadError error, string message)
    {
    if (placementId == rewardedVideoPlacement)
    isRewardedLoaded = false;
    Advertisement.Load(placementId);
    }
    }