- Home /
Admob rewarded video give more and more reward. Why
I have a shop scene where you can watch ad for 10 coin. Every time i open that scene give + 10 coin if i watch the ad.
So First time when i watch the ad give me 10 coin. When i leave the shop scene and go back and watch the ad will give me 20 coin. And again i leave the shop scene and go back and watch the ad will give me 30 coin. and so on.
Why is it for?
Can you post the code to analyse? Otherwise it's hard to tell.
Answer by Sonky108 · Jul 06, 2018 at 01:56 PM
The reason why this happen is because every Start you subscribe to an event without unsubscribing at all. Unsubscribe events on OnDestroy/OnDisable. Does multiple prints occured?
I tried that when i leave the scene destroy the script and when open the scene inserted the script but not worked. same issue!
did you think of this? @Sonky108
Destroying the script or the object is not a solution here. Every time you subscribe to something You have to unsubscribe. Without doing this RewardBaseVideoAd keeps reference to the callback preventing GarbageCollector from removing the object. Check the link below[https://docs.microsoft.com/en-us/dotnet/csharp/program$$anonymous$$g-guide/events/how-to-subscribe-to-and-unsubscribe-from-events] [1]
[1]: https://docs.microsoft.com/en-us/dotnet/csharp/program$$anonymous$$g-guide/events/how-to-subscribe-to-and-unsubscribe-from-events
Thank you :) work well. I dont know the admob's example why not contain this.
Answer by Oliversgame · Jul 06, 2018 at 03:47 AM
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds;
using GoogleMobileAds.Api;
using System;
public class rewardvideo : MonoBehaviour {
private RewardBasedVideoAd rewardBasedVideo;
public void Start()
{
// Get singlet on reward based video ad reference.
this.rewardBasedVideo = RewardBasedVideoAd.Instance;
// 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;
}
public void Update()
{
}
public void Clickonrewardreqest()
{
this.RequestRewardBasedVideo ();
//Debug.Log ("s");
}
public void Clickonrewardshow()
{
this.ShowRewardBasedVideo ();
}
private void RequestRewardBasedVideo()
{
string adUnitId = "ca-app-pub-3940256099942544/5224354917";
rewardBasedVideo.LoadAd (new AdRequest.Builder ().Build (), adUnitId);
}
private void ShowRewardBasedVideo()
{
if (this.rewardBasedVideo.IsLoaded())
{
this.rewardBasedVideo.Show();
}
else
{
MonoBehaviour.print("Reward based video ad is not ready yet");
}
}
#region RewardBasedVideo callback handlers
public void HandleRewardBasedVideoLoaded(object sender, EventArgs args)
{
MonoBehaviour.print("HandleRewardBasedVideoLoaded event received");
}
public void HandleRewardBasedVideoFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
MonoBehaviour.print(
"HandleRewardBasedVideoFailedToLoad event received with message: " + args.Message);
}
public void HandleRewardBasedVideoOpened(object sender, EventArgs args)
{
MonoBehaviour.print("HandleRewardBasedVideoOpened event received");
}
public void HandleRewardBasedVideoStarted(object sender, EventArgs args)
{
MonoBehaviour.print("HandleRewardBasedVideoStarted event received");
}
public void HandleRewardBasedVideoClosed(object sender, EventArgs args)
{
MonoBehaviour.print("HandleRewardBasedVideoClosed event received");
}
public void HandleRewardBasedVideoRewarded(object sender, Reward args)
{
coin.Coin += 10;
string type = args.Type;
double amount = args.Amount;
MonoBehaviour.print(
"HandleRewardBasedVideoRewarded event received for " + amount.ToString() + " " + type);
}
public void HandleRewardBasedVideoLeftApplication(object sender, EventArgs args)
{
MonoBehaviour.print("HandleRewardBasedVideoLeftApplication event received");
}
#endregion
}
Hmm, this is not enough info. What is coin.Coin? what is Amount? Do you use "amount" or "coin.Coin" to check what was awarded? Based on your code, i'd guess amount, but where do you get amount from? Is the player purse amount or coin.Coin? From what i see, i guess amount is the total amount in player's purse rather than the amount awarded. Can you check those?
@madks13 actually i dont know what is this line in the script:
double amount = args.Amount;
I find this whole script on the admob's website. Without this line work the same.
In fact just the coin.Coin need, that gives the reward. The coin.Coin is just a simple static integer.
Answer by Ex6tra · Jul 12, 2020 at 09:12 PM
Your problem is that you're subscribing to events more than once which results in the reward event being called more than once, to prevent that you should put your subscribing events in a method that only executes once like the Show reward ad method. if the problem occurs you should make sure that you're unsubscribing from the reward events every time the scene loads. In general you should subscribe when showing reward ad and unsubscribe when the player is rewarded
Your answer
Follow this Question
Related Questions
Admob video ad shows only once on the phone ? 1 Answer
admob legacy api can load multiple video ads but new api doesn't ? 0 Answers
Video Ads not showing correctly on IOS 1 Answer
Admob Reward video not showing up, but the test ad unit is showing. 2 Answers
admob rewarded video ad dont reward 1 Answer