Search Unity

OnUnityAdsShowComplete not getting called

Discussion in 'Scripting' started by danjam84, Jul 26, 2021.

  1. danjam84

    danjam84

    Joined:
    Nov 24, 2019
    Posts:
    1
    What I want to achieve:- Show an interstitial ad. And after the ad has completed - either on clicking Close or on clicking Skip - do something.

    I'm using Advertisement Package 3.7.3

    I've used the example code from Unity. Added Debug.Log statements to the functions.

    The test ad is showing in the editor. But on clicking Close or Skip, whatever I've added to OnUnityAdsShowComplete function (including the Debug.Log) statement doesn't run).

    Not sure what I am doing wrong

    My code
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Advertisements;
    3.  
    4. public class InterstitialAdExample : MonoBehaviour, IUnityAdsLoadListener, IUnityAdsShowListener
    5. {
    6.     [SerializeField] string _androidAdUnitId = "Interstitial_Android";
    7.     [SerializeField] string _iOsAdUnitId = "Interstitial_iOS";
    8.     string _adUnitId;
    9.  
    10.     void Awake()
    11.     {
    12.         _adUnitId = (Application.platform == RuntimePlatform.IPhonePlayer)
    13.             ? _iOsAdUnitId
    14.             : _androidAdUnitId;
    15.     }
    16.  
    17.     public void LoadAd()
    18.     {
    19.         // I call LoadAd() on clicking a button.
    20.         Debug.Log("Loading Ad: " + _adUnitId);
    21.         Advertisement.Load(_adUnitId, this);
    22.     }
    23.  
    24.     public void OnUnityAdsAdLoaded(string adUnitId)
    25.     {
    26.         ShowAd();
    27.     }
    28.  
    29.     public void OnUnityAdsFailedToLoad(string adUnitId, UnityAdsLoadError error, string message)
    30.     {
    31.         Debug.Log($"Error loading Ad Unit: {adUnitId} - {error.ToString()} - {message}");
    32.     }
    33.  
    34.     public void ShowAd()
    35.     {
    36.         Debug.Log("Showing Ad: " + _adUnitId);
    37.         Advertisement.Show(_adUnitId, this);
    38.     }
    39.  
    40.     public void OnUnityAdsShowFailure(string adUnitId, UnityAdsShowError error, string message)
    41.     {
    42.         Debug.Log($"Error showing Ad Unit {adUnitId}: {error.ToString()} - {message}");
    43.     }
    44.  
    45.     public void OnUnityAdsShowStart(string adUnitId)
    46.     {
    47.         Debug.Log("Ad started showing");
    48.  
    49.     }
    50.     public void OnUnityAdsShowClick(string adUnitId) { }
    51.     public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState)
    52.     {
    53.         Debug.Log("Ad complete");
    54.         //Tried adding actions here, but it doesn't run
    55.     }
    56. }
     
  2. motifransis

    motifransis

    Joined:
    Dec 12, 2017
    Posts:
    4
    same problem for me (i did a work around by adding IUnityAdsListener interface and implemrnting its methods and there the IUnityAdsListener.OnUnityAdsDidFinish callback is called with results but i would like it to work like its ment to)