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

Admob Rewarded Video, wrong rewards.

$
0
0
Hello! I have implemented rewarded video ads on my game but every time I watch them i get wrong rewards. I have an ad that duplicate the coins that you get in a gift. I also have a different ad that gives your +20 coins. When i watch an ad for the first time everything is okay, but the second time I watch it the rewards are duplicated. For example, if first i watch an ad and duplicate the coins from the gift, then watch an ad to get +20 coins, instead of getting 20 coins i get 20 coins plus the coins from the gift. This is the script for getting the double coins from the gift using System.Collections; using System.Collections.Generic; using UnityEngine; using GoogleMobileAds; using GoogleMobileAds.Api; public class DoubleCoinsAD : MonoBehaviour { //REWARD AD VARIABLES private RewardBasedVideoAd rewardBasedVideo; // Start is called before the first frame update void Start() { // Get singleton reward based video ad reference this.rewardBasedVideo = RewardBasedVideoAd.Instance; // Called when the ad starts to play. rewardBasedVideo.OnAdStarted += HandleRewardBasedVideoStarted; // Called when the user should be rewarded for watching a video. rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded; // Called when the ad is closed. rewardBasedVideo.OnAdClosed += HandleRewardBasedVideoClosed; RequestRewardBasedVideo(); } private void RequestRewardBasedVideo() { #if UNITY_ANDROID string adUnitId = ""; #elif UNITY_IPHONE string adUnitId = ""; #else string adUnitId = "unexpected_platform"; #endif // Create an empty ad request. AdRequest request = new AdRequest.Builder().Build(); // Load the rewarded video ad with the request. this.rewardBasedVideo.LoadAd(request, adUnitId); } public void ShowRewardBasedAd() { if (rewardBasedVideo.IsLoaded()) { rewardBasedVideo.Show(); } else { MonoBehaviour.print("yo, its not showing"); } } //video started public void HandleRewardBasedVideoStarted(object sender, System.EventArgs args) { MonoBehaviour.print("HandleRewardBasedVideoStarted event received"); Time.timeScale = 0; } //video is closed public void HandleRewardBasedVideoClosed(object sender, System.EventArgs args) { MonoBehaviour.print("HandleRewardBasedVideoClosed event received"); Time.timeScale = 1; this.RequestRewardBasedVideo(); } //video is watched and then user rewarded public void HandleRewardBasedVideoRewarded(object sender, Reward args) { string type = args.Type; double amount = args.Amount; Time.timeScale = 1; SaveManager.Instance.DoubleGift(); MonoBehaviour.print( "HandleRewardBasedVideoRewarded event received for " + amount.ToString() + " " + type); } } This is the script for getting +20 coins using System.Collections; using System.Collections.Generic; using UnityEngine; using GoogleMobileAds; using GoogleMobileAds.Api; public class GetCoinsAD : MonoBehaviour { //REWARD AD VARIABLES private RewardBasedVideoAd rewardBasedVideo; // Start is called before the first frame update void Start() { // Get singleton reward based video ad reference this.rewardBasedVideo = RewardBasedVideoAd.Instance; // Called when the ad starts to play. rewardBasedVideo.OnAdStarted += HandleRewardBasedVideoStarted; // Called when the user should be rewarded for watching a video. rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded; // Called when the ad is closed. rewardBasedVideo.OnAdClosed += HandleRewardBasedVideoClosed; RequestRewardBasedVideo(); } private void RequestRewardBasedVideo() { #if UNITY_ANDROID string adUnitId = ""; #elif UNITY_IPHONE string adUnitId = ""; #else string adUnitId = "unexpected_platform"; #endif // Create an empty ad request. AdRequest request = new AdRequest.Builder().Build(); // Load the rewarded video ad with the request. this.rewardBasedVideo.LoadAd(request, adUnitId); } public void ShowRewardBasedAd() { if (rewardBasedVideo.IsLoaded()) { rewardBasedVideo.Show(); } else { MonoBehaviour.print("yo, its not showing"); } } //video started public void HandleRewardBasedVideoStarted(object sender, System.EventArgs args) { MonoBehaviour.print("HandleRewardBasedVideoStarted event received"); Time.timeScale = 0; } //video is closed public void HandleRewardBasedVideoClosed(object sender, System.EventArgs args) { MonoBehaviour.print("HandleRewardBasedVideoClosed event received"); Time.timeScale = 1; this.RequestRewardBasedVideo(); } //video is watched and then user rewarded public void HandleRewardBasedVideoRewarded(object sender, Reward args) { string type = args.Type; double amount = args.Amount; Time.timeScale = 1; SaveManager.Instance.GetCoins(); MonoBehaviour.print( "HandleRewardBasedVideoRewarded event received for " + amount.ToString() + " " + type); } } And this are the functions (the rewards) public void DoubleGift() { giftCoins = giftCoins * 2; GameManager.Instance.coins += giftCoins; giftCoinsText.text = "" + giftCoins; doubleCoins.SetActive(false); } public void GetCoins() { GameManager.Instance.coins += 20; getCoins.SetActive(false); } Thank you in advance!

Viewing all articles
Browse latest Browse all 1416

Trending Articles



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