Hi,
I've been trying to implement the events for a rewarded video in a project i'm doing in Unity. The rewarded video shows up finely, but the Events don't seem to fire up, and therefore can't reward my user or other things.
I've searched in every forum, and one of the things i've tried is dispatching the events to the main threads, but that don't seem to work either, and i don't know what to do anymore.
Here under i post my code. I've erased my app ID and unit ID here, but they are in my original code. The Interstitial is shown when "Game over" happens from an external class, and the rewarded video is shown when the user chooses to in a pop-up window, which is also proceeding from another class.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using GoogleMobileAds.Api;
public class Admanager : MonoBehaviour {
private InterstitialAd interstitial;
private RewardBasedVideoAd rewardBasedVideo;
public void Start()
{
UnityMainThreadDispatcher.Instance().Enqueue(() => Debug.Log("This is executed from the main thread"));
// Initialize the Google Mobile Ads SDK.
MobileAds.Initialize(appId);
//this.RequestInterstitial();
this.rewardBasedVideo = RewardBasedVideoAd.Instance;
// Called when an ad request has successfully loaded.
rewardBasedVideo.OnAdLoaded += HandleRewardBasedVideoLoaded;
// Called when an ad request failed to load.
rewardBasedVideo.OnAdFailedToLoad += HandleRewardBasedVideoFailedToLoad;
// Called when an ad is shown.
rewardBasedVideo.OnAdOpening += HandleRewardBasedVideoOpened;
// 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;
// Called when the ad click caused the user to leave the application.
rewardBasedVideo.OnAdLeavingApplication += HandleRewardBasedVideoLeftApplication;
this.RequestRewardBasedVideo();
this.RequestInterstitial();
}
// Update is called once per frame
void Update () {
}
public void playInter(){
if (this.interstitial.IsLoaded())
{
this.interstitial.Show();
}
}
public void playReward(){
if (rewardBasedVideo.IsLoaded())
{
rewardBasedVideo.Show();
}
}
public void destroyInter(){
interstitial.Destroy();
}
private void RequestRewardBasedVideo()
{
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the rewarded video ad with the request.
this.rewardBasedVideo.LoadAd(request, adUnitId);
}
private void RequestInterstitial()
{
// Initialize an InterstitialAd.
this.interstitial = new InterstitialAd(adUnitId);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the interstitial with the request.
this.interstitial.LoadAd(request);
}
public void HandleRewardBasedVideoLoaded(object sender, System.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, System.EventArgs args)
{
MonoBehaviour.print("HandleRewardBasedVideoOpened event received");
}
public void HandleRewardBasedVideoStarted(object sender, System.EventArgs args)
{
MonoBehaviour.print("HandleRewardBasedVideoStarted event received");
}
public void HandleRewardBasedVideoClosed(object sender, System.EventArgs args)
{
MonoBehaviour.print("HandleRewardBasedVideoClosed event received");
this.RequestRewardBasedVideo();
}
public void HandleRewardBasedVideoRewarded(object sender, Reward args)
{
string type = args.Type;
double amount = args.Amount;
MonoBehaviour.print(
"HandleRewardBasedVideoRewarded event received for "
+ amount.ToString() + " " + type);
}
public void HandleRewardBasedVideoLeftApplication(object sender, System.EventArgs args)
{
MonoBehaviour.print("HandleRewardBasedVideoLeftApplication event received");
}
}
Will appreciate any help, thank you very much!!