Search Unity

How to Implement the Show Listener's OnUnityAdsShowComplete callback method

Discussion in 'Unity Ads & User Acquisition' started by Romyo75, Sep 14, 2021.

  1. Romyo75

    Romyo75

    Joined:
    Sep 8, 2021
    Posts:
    14
    Hi, the code tells me
    Code (CSharp):
    1. // Implement the Show Listener's OnUnityAdsShowComplete callback method to determine if the user gets a reward:
    2.     public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState)
    3.     {
    4.         if (adUnitId.Equals(_adUnitId) && showCompletionState.Equals(UnityAdsShowCompletionState.COMPLETED))
    5.         {
    6.             Debug.Log("Unity Ads Rewarded Ad Completed");
    7.             // Grant a reward.
    8.            
    9.            
    10.          
    11.             // Load another ad:
    12.             Advertisement.Load(_adUnitId, this);
    13.         }
    14.     }
    So question is how to /Implement the Show Listener's OnUnityAdsShowComplete callback method to determine if the user gets a reward?
     
  2. ej-Unity

    ej-Unity

    Unity Technologies

    Joined:
    May 13, 2021
    Posts:
    27
    Hi,

    As is described in this guide, you should create two C# scripts
    1. AdsInitializer
    2. RewardedAdsButton
    Ad these scripts to your scene and create a button to play the rewarded ad.

    Note: Make sure you call the method LoadAd() in RewardedAdsButton Script, after the initialization.

    Ex.
    Code (CSharp):
    1. //AdsInitializer class
    2. public void OnInitializationComplete()
    3. {
    4.         Debug.Log("Unity Ads initialization complete.");
    5.         _rewardedAdsButton.LoadAd();
    6. }
     
  3. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    @Esteban_Unity_COL is that guide updated for the new dialog Unity pops up the first time the game plays an ad? we had our code working fine until this new thing appeared and now the first ad always gets a
    OnUnityAdsDidError event triggered ... are these both things correlated?
     
  4. ej-Unity

    ej-Unity

    Unity Technologies

    Joined:
    May 13, 2021
    Posts:
    27
    Hi @pistoleta, yes, that guide is updated, looks like you have an issue with your code implementation, please open a ticket here, I will be happy to help you.
     
  5. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    Thanks we already did.