In Rewarded Video Ads not work reward

In Rewarded Video Ads not work reward

7847790--995271--image002.jpg

Place a GameObject on Scene (UnityAdsManager)

7847790--995274--image004.jpg

Place a Button on Scene (TestButton with btnTestAdsManager.cs )

It used:
https://docs.unity.com/ads/UnityDeveloperIntegrations.htm

To initialize Unity Ads SDK
https://docs.unity.com/ads/InitializingTheUnitySDK.htm

To show reward video
https://docs.unity.com/ads/ImplementingRewardedAdsUnity.htm

AdsInitializer.cs

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

public class AdsInitializer : MonoBehaviour, IUnityAdsInitializationListener
{
    [SerializeField] private string _androidGameId = "39XXXXX";
    [SerializeField] private string _iOSGameId = "39XXXXX"; 
    private string _gameId;

    void Awake()
    {
        InitializeAds();
    }

    public void InitializeAds()
    {
        _gameId = (Application.platform == RuntimePlatform.IPhonePlayer)
            ? _iOSGameId
            : _androidGameId;

        Advertisement.Initialize(_gameId, false);
     
    }

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

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

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Advertisements;

public class RewardedAds : MonoBehaviour, IUnityAdsLoadListener, IUnityAdsShowListener
{
     public string _adUnitId = null;
    public string AndroidAdID = "39XXXXX";
    public string iOSAdID = "39XXXXX";
       // Get the Ad Unit ID for the current platform:

    void Awake()
    {

#if UNITY_IOS
         _adUnitId = iOSAdID;
#endif

#if UNITY_ANDROID
        _adUnitId = AndroidAdID;
#endif

    }



    // Load content to the Ad Unit:
    public void LoadAd()
    {
        // IMPORTANT! Only load content AFTER initialization (in this example, initialization is handled in a different script).
        Debug.Log("Loading Ad: " + _adUnitId);
          Advertisement.Load(_adUnitId, this);
    }

    // If the ad successfully loads, add a listener to the button and enable it:
    public void OnUnityAdsAdLoaded(string adUnitId)
    {
        Debug.Log("Ad Loaded: " + adUnitId);

        if (adUnitId.Equals(_adUnitId))
        {
         
        }
    }

    // Implement a method to execute when the user clicks the button.
    public void ShowAd()
    {
        // Then show the ad:
          Advertisement.Show(_adUnitId, this);
     }

    // Implement the Show Listener's OnUnityAdsShowComplete callback method to determine if the user gets a reward:
    public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState)
    {
                if (adUnitId.Equals(_adUnitId) && showCompletionState.Equals(UnityAdsShowCompletionState.COMPLETED))
        {
            Debug.Log("Unity Ads Rewarded Ad Completed");
            // Grant a reward.
            int icoin = PlayerPrefs.GetInt("coin");
            icoin = icoin + 1;
            PlayerPrefs.SetInt("coin", icoin);

            // Load another ad:
            Advertisement.Load(_adUnitId, this);
         }
    }

    // Implement Load and Show Listener error callbacks:
    public void OnUnityAdsFailedToLoad(string adUnitId, UnityAdsLoadError error, string message)
    {
        Debug.Log($"Error loading Ad Unit {adUnitId}: {error.ToString()} - {message}");
        // Use the error details to determine whether to try to load another ad.
    }

    public void OnUnityAdsShowFailure(string adUnitId, UnityAdsShowError error, string message)
    {
        Debug.Log($"Error showing Ad Unit {adUnitId}: {error.ToString()} - {message}");
        // Use the error details to determine whether to try to load another ad.
    }

    public void OnUnityAdsShowStart(string adUnitId) { }
    public void OnUnityAdsShowClick(string adUnitId) { }

    void OnDestroy()
    {
        // Clean up the button listeners:
    }
}
btnTestAdsManager.cs

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

public class btnTestAdsManager : MonoBehaviour
{
    Button btnTestAds;
#if UNITY_IOS
             string adUnitId = "39XXXXX";
#endif

#if UNITY_ANDROID
    //   _adUnitId = _androidAdUnitId;
    string adUnitId = "39XXXXX";
#endif


    // Start is called before the first frame update
    void Start()
    {
        btnTestAds = GameObject.Find("btnTestAds1").gameObject.GetComponent<Button>();

        btnTestAds.onClick.AddListener(() => {
            if ((Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork)
               || (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork))
            {
                //
                  RewardedAds ms = new RewardedAds();           
                  ms.ShowAd();
                  ms.OnUnityAdsShowComplete(adUnitId, UnityAdsShowCompletionState.COMPLETED);             
            }
        });
    }
}

OR

btnTestAds.onClick.AddListener(() => {
            if ((Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork)
               || (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork))
            {
                //
                  RewardedAds ms = new RewardedAds();           
                  ms.ShowAd();               
            }
        });

When I press Button (TestAds) , Ads is shown, but reward not work (reward for showing ads not received)

If I use:

btnTestAds.onClick.AddListener(() => {
            if ((Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork)
               || (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork))
            {
                //
       GameObject.Find("UnityAdsManager").GetComponent<RewardedAds>().ShowAd();
            }
        });

That receive error in log
Error showing Ad Unit 39XXXXX: NOT_READY - Placement 39XXXXX is not ready

Hi,

I think you are using the wrong ad unit ids. Ad unit ids are different from game id. It should be the id shown in the “Ad Units”.

Game Id from here

Hm… very Thanks… It’s worked

void Awake()
    {
#if UNITY_IOS   
     _adUnitId = "rewardedVideo";
#endif

#if UNITY_ANDROID       
        _adUnitId = "rewardedVideo";
#endif
    }

Then I have another question in addition

btnTestAds.onClick.AddListener(() => {
            if ((Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork)
               || (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork))
            {GameObject.Find("UnityAdsManager").GetComponent<RewardedAds>().ShowAd();
            }
        });

when I click the Button (btnTestAds) One time, Ads shown , reward is received - It’s OK
But when I click the Button ( btnTestAds) second time, Ads shown, but I get double reward…
when I click the Button ( btnTestAds) third time, Ads shown, but I get triple reward…
I think “btnTestAds.onClick.AddListener” - doubles, triples, etc…
How to do “btnTestAds.onClick.AddListener” to no doubles, triples, etc ?

Hi @ab2700kd ,

This is a known issue that occurs only within the Unity Editor. We are currently working on a fix.

As a potential workaround to make testing in the editor easier, you may want to consider keeping track of whether or not an ad has been shown (and a listener added) and adding the listener as appropriate. See the below code snippet as an example.

#if UNITY_EDITOR
        if (adsShownThisSession == 0)
        {
            Advertisement.Show(_adUnitId, this);
            adsShownThisSession++;
        }
        else
        {
            Advertisement.Show(_adUnitId);
        }
#else
            Advertisement.Show(_adUnitId, this);
#endif

Thank you for your patience while we work on fixing this issue!

Thanks, On real device Test Unity Ads work perfectly!