- Home /
Question by
Darkeriol · Sep 13, 2017 at 05:10 PM ·
adsadvertising
Problem with ads reward
I copied the code from this guide: https://unity3d.com/learn/tutorials/topics/production/services-integrating-unity-ads
The problem is that clicking multiple times on the advertising button before it is loaded, when the ad is displayed, the player earns the reward several times seeing only one single video. Can I also include a function that verifies whether or not the connection is present?
This is the code:
using UnityEngine;
using System.Collections;
using UnityEngine.Advertisements;
public class AdManager : MonoBehaviour
{
[SerializeField] string gameID = "";
void Awake()
{
Advertisement.Initialize (gameID, true);
}
//rewardedVideo
public void ShowAd(string zone = "")
{
#if UNITY_EDITOR
StartCoroutine(WaitForAd ());
#endif
if (string.Equals (zone, ""))
zone = null;
ShowOptions options = new ShowOptions ();
options.resultCallback = AdCallbackhandler;
if (Advertisement.IsReady (zone))
Advertisement.Show (zone, options);
}
void AdCallbackhandler (ShowResult result)
{
switch(result)
{
case ShowResult.Finished:
Debug.Log ("Ad Finished. Rewarding player...");
Data.coin += 300;
break;
case ShowResult.Skipped:
Debug.Log ("Ad skipped. Son, I am dissapointed in you");
break;
case ShowResult.Failed:
Debug.Log("I swear this has never happened to me before");
break;
}
}
IEnumerator WaitForAd()
{
float currentTimeScale = Time.timeScale;
Time.timeScale = 0f;
yield return null;
while (Advertisement.isShowing)
yield return null;
Time.timeScale = currentTimeScale;
}
}
Comment
Your answer
Follow this Question
Related Questions
Unity ads problem for mobile 0 Answers
How do you monetize games for Windows Phone, Windows (PC) and the Web? 0 Answers
Ad IsReady problem 2 Answers
OnUnityAdsShowComplete not working 2 Answers
Tiny Banner Ad problem? 1 Answer