Quantcast
Channel: Questions in topic: "ads"
Viewing all articles
Browse latest Browse all 1416

Problem with ads reward

$
0
0
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; } }

Viewing all articles
Browse latest Browse all 1416

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>