- Home /
Not sure how to get OnUnityAdsShowClick working. Please help.
What I'm trying to achieve:- Play an Interstitial ad. And then run a function only once the ad has been completed/skipped/closed..
Using Advertisement Package 3.7.3
I'm using the example code form the Unity doc. Added LoadAd() to the click action of a button. And called ShowAd() from OnUnityAdsAdLoaded(). The test ad is showing up in the editor, but on clicking Close or Skip nothing is happening.. In fact nothing that I add to OnUnityAdsShowClick is running, not even the Debug.log statement.
I'm a newbie. Not sure what I'm doing wrong. Here is my code.
using UnityEngine;
using UnityEngine.Advertisements;
public class InterstitialAdExample : MonoBehaviour, IUnityAdsLoadListener, IUnityAdsShowListener
{
[SerializeField] string _androidAdUnitId = "Interstitial_Android";
[SerializeField] string _iOsAdUnitId = "Interstitial_iOS";
string _adUnitId;
void Awake()
{
_adUnitId = (Application.platform == RuntimePlatform.IPhonePlayer)
? _iOsAdUnitId
: _androidAdUnitId;
}
public void LoadAd()
{
// I call LoadAd() on clicking a button.
Debug.Log("Loading Ad: " + _adUnitId);
Advertisement.Load(_adUnitId, this);
}
public void OnUnityAdsAdLoaded(string adUnitId)
{
ShowAd();
}
public void OnUnityAdsFailedToLoad(string adUnitId, UnityAdsLoadError error, string message)
{
Debug.Log($"Error loading Ad Unit: {adUnitId} - {error.ToString()} - {message}");
}
public void ShowAd()
{
Debug.Log("Showing Ad: " + _adUnitId);
Advertisement.Show(_adUnitId, this);
}
public void OnUnityAdsShowFailure(string adUnitId, UnityAdsShowError error, string message)
{
Debug.Log($"Error showing Ad Unit {adUnitId}: {error.ToString()} - {message}");
}
public void OnUnityAdsShowStart(string adUnitId)
{
Debug.Log("Ad started showing");
}
public void OnUnityAdsShowClick(string adUnitId) { }
public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState)
{
Debug.Log("Ad complete");
//Tried adding actions here, but it doesn't run
}
}
Answer by danjam84 · Sep 30, 2021 at 03:55 PM
Contacted Unity - according to their response "the event OnUnityAdsShowComplete() is called after the ad is shown, however, this only happens in the build."
Your answer
Follow this Question
Related Questions
Unity Ads Banner not working. 0 Answers
[HELP] Unity ADS 1 Answer
can i use unity ads as well as facebook ads in my unity android project? 0 Answers
UnityAds.h Not Found 1 Answer