EDIT2: I solved my issue by setting a variable “hasPlayed = false” immediately after ShowVid() is called, have and then changed the first if statement to reflect:
if (adState.Equals ("available") && hasPlayed == false) {
HZIncentivizedAd.Show ();
hasPlayed = true;
}
I feel like this is a work-around, and not the proper answer as it was designed, so I’ll leave the question open and implement any suggestion for the right way of doing it and mark that as the answer.
Hello!
I’m using HeyZap, with UnityAds as the provider for Rewarded Videos. I’d like it so if the user presses a button, it shows a video ad, then rewards them afterwards. I’ve gotten them working on my Android, but after you click “X” after the video finishes, another one automatically plays. Here is my code:
public void ShowVid ()
{
HZIncentivizedAd.Fetch ();
HZIncentivizedAd.AdDisplayListener listener = delegate(string adState, string adTag) {
if (adState.Equals ("available")) {
HZIncentivizedAd.Show ();
}
if (adState.Equals("fetch_failed") ) {
//TELL USER TO CHECK CONNECTION
}
if (adState.Equals ("incentivized_result_complete")) {
if (PlayerPrefs.HasKey ("Points"))
PlayerPrefs.SetInt ("Points", PlayerPrefs.GetInt ("Points") + 10);
else
PlayerPrefs.SetInt ("Points", PlayerPrefs.GetInt ("Points") + 10);
return;
}
if (adState.Equals ("incentivized_result_incomplete")) {
// The user did not watch the entire video and should not be given a reward.
}
if (adState.Equals("audio_starting") ) {
// The ad about to be shown will need audio.
// Mute any background music.
}
if (adState.Equals("audio_finished") ) {
// The ad being shown no longer needs audio.
// Any background music can be resumed.
}
};
HZIncentivizedAd.SetDisplayListener (listener);
}
Please let me know if you see anything wrong with this!
EDIT: Is there supposed to be a function to destroy the listener? I can’t seem to find anything in docs or APIs.