Ads Failed


Hi , I have Ads Failed
I checked from everything

Paste in your Admanager script and we’ll have a look

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

public class AdManager : MonoBehaviour, IUnityAdsListener
{
    [SerializeField] private bool testMode = true;

    public static AdManager Instance; // this called singelton which mean (fixed) one object in all scenes

#if UNITY_ANDROID
    private string gameId = "5104365";
#elif UNITY_IOS
    private string gameId = "5104364";
#endif

    private GameOverHandler gameOverHandler;

    void Awake()
    {
        if (Instance != null && Instance != this) // if we have one Instance destroy this one 
                                                  //it's to stop us to have mone one
        {
            Destroy(gameObject);
        }
        else
        {
            Instance = this;
            DontDestroyOnLoad(gameObject); //that means is now when we change scenes, this object is not
                                           //destroyed which is exactly what we want

            Advertisement.AddListener(this);
            Advertisement.Initialize(gameId, testMode); //this variable testmode we have for wether
                                                    //we should use test ad or real ads
        }

    }

    public void ShowAd(GameOverHandler gameOverHandler) //after watch ads continue in OnUnityAdsDidFinish
    {
        this.gameOverHandler = gameOverHandler;

        Advertisement.Show("rewardedVideo");
    }

    public void OnUnityAdsReady(string placementId)
    {
        Debug.Log("Unity Ads Ready");
    }

    public void OnUnityAdsDidError(string message)
    {
        Debug.LogError($"Unity Ads Error{message}");
    }

    public void OnUnityAdsDidStart(string placementId)
    {
        Debug.Log("Ads Started");
    }

    public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
    {
        switch (showResult)
        {
            case ShowResult.Finished:
                gameOverHandler.ContinueGame();
                break;
            case ShowResult.Skipped:
                //we was skipped
                break;
            case ShowResult.Failed:
                Debug.LogWarning("Ads Failed");
                break;
        }


    }

   

}

It looks like you’re working off of an older version of ads (see the lecture Ads 4.0). Here’s a copy of the script along with some further updates, as we also have to Load the ads manually now (Unity keeps changing the ads protocols faster than we can update videos).

using UnityEngine;
using UnityEngine.Advertisements;

public class AdManager : MonoBehaviour, IUnityAdsInitializationListener, IUnityAdsLoadListener, IUnityAdsShowListener
{
    [SerializeField] private bool testMode = true;

    public static AdManager Instance;

#if UNITY_ANDROID
    private string gameId = "Put your Android gameID here";
#elif UNITY_IOS
    private string gameId = "Put your iOS gameID here";
    #else
        private string gameId = "Not Available";
    #endif

    private GameOverHandler gameOverHandler;

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

            Advertisement.Initialize(gameId, testMode, this);
        }
    }

    public void OnInitializationComplete()
    {
        Debug.Log("Unity Ads initialization complete.");
        Advertisement.Load("rewardedVideo"); 
    }

    public void OnInitializationFailed(UnityAdsInitializationError error, string message)
    {
        Debug.Log($"Unity Ads Initialization Failed: {error} - {message}");
    }

    public void ShowAd(GameOverHandler gameOverHandler)
    {
        this.gameOverHandler = gameOverHandler;

        Advertisement.Show("rewardedVideo", this);
    }

    public void OnUnityAdsAdLoaded(string placementId)
    {
        Debug.Log($"Ad Loaded: {placementId}");
    }

    public void OnUnityAdsFailedToLoad(string placementId, UnityAdsLoadError error, string message)
    {
        Debug.Log($"Error loading Ad Unit {placementId}: {error} - {message}");
    }

    public void OnUnityAdsShowFailure(string placementId, UnityAdsShowError error, string message)
    {
        Debug.Log($"Error showing Ad Unit {placementId}: {error} - {message}");
    }

    public void OnUnityAdsShowStart(string placementId) { }

    public void OnUnityAdsShowClick(string placementId) { }

    public void OnUnityAdsShowComplete(string placementId, UnityAdsShowCompletionState showCompletionState)
    {
        Advertisement.Load("rewardedVideo");
        switch (showCompletionState)
        {
            case UnityAdsShowCompletionState.COMPLETED:
                gameOverHandler.ContinueGame();
                break;
            case UnityAdsShowCompletionState.SKIPPED:
                // Ad was skipped
                break;
            case UnityAdsShowCompletionState.UNKNOWN:
                Debug.LogWarning("Ad Failed");
                break;
        }
    }
}

thank you , I use it
I tried from unity gaming services to use ( rewarded )which I create it is not work
but when I use (Rewarded_Android) it is work


what is different ?

It may just be that Unity Ads doesn’t like just “rewarded” as the placement. To be honest, I’m not sure. That’s something you may need to ask on the Unity Forums.

Privacy & Terms