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

admob rewarded ad does not give reward change scene

$
0
0
i use google admob rewarded ad, ad give the reward but when i change the scene and come back main scene, ad still watching but does not give reward. There is my code: using System.Collections; using System.Collections.Generic; using UnityEngine; using GoogleMobileAds; using GoogleMobileAds.Api; using System; using UnityEngine.UI; public class Admob_Manager : MonoBehaviour { public string Rewarded_ID; public GameObject repanel; RewardBasedVideoAd rewardBasedVideo; void Start () { rewardBasedVideo = RewardBasedVideoAd.Instance; repanel.SetActive(false); RequestRewardBasedVideo(); // RewardBasedVideoAd is a singleton, so handlers should only be registered once. this.rewardBasedVideo.OnAdLoaded += this.HandleRewardBasedVideoLoaded; this.rewardBasedVideo.OnAdFailedToLoad += this.HandleRewardBasedVideoFailedToLoad; this.rewardBasedVideo.OnAdOpening += this.HandleRewardBasedVideoOpened; this.rewardBasedVideo.OnAdStarted += this.HandleRewardBasedVideoStarted; this.rewardBasedVideo.OnAdRewarded += this.HandleRewardBasedVideoRewarded; this.rewardBasedVideo.OnAdClosed += this.HandleRewardBasedVideoClosed; this.rewardBasedVideo.OnAdLeavingApplication += this.HandleRewardBasedVideoLeftApplication; } // Update is called once per frame void Update () { } // Returns an ad request with custom ad targeting. private AdRequest CreateAdRequest() { return new AdRequest.Builder().Build(); } public void RequestRewardBasedVideo() { #if UNITY_EDITOR string adUnitId = "unused"; #elif UNITY_ANDROID string adUnitId = Rewarded_ID; #elif UNITY_IPHONE string adUnitId = Rewarded_ID; #else string adUnitId = "unexpected_platform"; #endif this.rewardBasedVideo.LoadAd(this.CreateAdRequest(), adUnitId); } public void ShowRewardBasedVideo() { if(rewardBasedVideo.IsLoaded()) { rewardBasedVideo.Show(); } else { Debug.Log("Rewarded Ad Load"); } } #region RewardBasedVideo callback handlers public void HandleRewardBasedVideoLoaded(object sender, EventArgs args) { } public void HandleRewardBasedVideoFailedToLoad(object sender, AdFailedToLoadEventArgs args) { } public void HandleRewardBasedVideoOpened(object sender, EventArgs args) { } public void HandleRewardBasedVideoStarted(object sender, EventArgs args) { } public void HandleRewardBasedVideoClosed(object sender, EventArgs args) { RequestRewardBasedVideo(); } public void HandleRewardBasedVideoRewarded(object sender, Reward args) { string type = args.Type; double amount = args.Amount; repanel.SetActive(true); } public void HandleRewardBasedVideoLeftApplication(object sender, EventArgs args) { MonoBehaviour.print("HandleRewardBasedVideoLeftApplication event received"); } #endregion }

Viewing all articles
Browse latest Browse all 1416

Trending Articles