- Home /
Admob rewarded videos not rewarding
I have implemented a rewarded video in my 2D unity game. I can watch the video but when it is done, the method called when the video is complete is not called. Here is my script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using GoogleMobileAds.Api;
public class rewardedVideoDrops : MonoBehaviour {
private RewardBasedVideoAd rewardBasedVideo;
public money money;
Button button;
bool loaded = false;
bool reward = false;
public void Start()
{
loaded = true;
reward = false;
button = GameObject.Find ("addDrops").GetComponent <Button> ();
this.rewardBasedVideo = RewardBasedVideoAd.Instance;
this.rewardBasedVideo.OnAdLoaded += this.HandleRewardBasedVideoLoaded;
this.rewardBasedVideo.OnAdRewarded += this.HandleRewardBasedVideoRewarded;
this.RequestRewardedVideo();
}
void Update () {
if (reward == true) {
money.UpdateMoney (PlayerPrefs.GetInt ("money") + 100);
this.RequestRewardedVideo();
reward = false;
loaded = false;
}
if (loaded == true) {
button.interactable = true;
} else {
button.interactable = false;
}
}
private void RequestRewardedVideo()
{
#if UNITY_ANDROID
string adUnitId = "ca-app-pub-3940256099942544/5224354917";
#elif UNITY_IPHONE
string adUnitId = "ca-app-pub-3940256099942544/1712485313";
#else
string adUnitId = "unexpected_platform";
#endif
AdRequest request = new AdRequest.Builder().Build();
this.rewardBasedVideo.LoadAd(request, adUnitId);
}
public void showVideo () {
if (rewardBasedVideo.IsLoaded()) {
rewardBasedVideo.Show();
}
}
public void HandleRewardBasedVideoLoaded(object sender, EventArgs args)
{
loaded = true;
}
public void HandleRewardBasedVideoRewarded(object sender, Reward args)
{
loaded = false;
reward = true;
}
}
By the way, I have another rewarded video in another scene and it works fine. I use the same base code and just changed what happens when loaded is true and when rewarded is true.
I have tried looking on the internet and found that if you removed all handlers except the reward handler but this doesn't work. What puzzles me the most is at the same script (well nearly at least) works fine in one scene but not in the other.
Answer by RER1200 · Dec 26, 2017 at 10:14 AM
I've fixed the issue. The solution was really simple because the problem was a very dumb mistake. I forgot to set money to a money script. In Start I added
money = GameObject.Find ("Money").GetComponent <money> ()
and also, in Start, it is not loaded = true;
but loaded = false;