1

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;
using UnityEngine.UI;

public class admobVideo : MonoBehaviour {

 RewardBasedVideoAd rewardBasedVideo;

 static InterstitialAd interstitial;

 string VideoID = "ca-app-pub-6032262586397129~2821965113";
 string adUnitId = "ca-app-pub-6032262586397129/5003220953";

 public static admobVideo Instance;
 void Start ()
 {
  Instance = this;
  DontDestroyOnLoad(gameObject);
  RequestRewardBasedVideo();
  RequestInterstitial();
 }

 public void RequestRewardBasedVideo()
 {       
  rewardBasedVideo = RewardBasedVideoAd.Instance;
  rewardBasedVideo.LoadAd(new AdRequest.Builder().Build(), adUnitId);
 }

 public void RequestInterstitial()
 {
  interstitial = new InterstitialAd(VideoID);
  interstitial.LoadAd(new AdRequest.Builder().Build());
 }
 public void ShowAd()
 {
  if(rewardBasedVideo.IsLoaded())
  {
   rewardBasedVideo.Show();
   rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
  }
 }
 public static void ShowInter()
 {
  showInterstitial(interstitial);
 }


 private void showAdd(RewardBasedVideoAd r)
 {
  if (r.IsLoaded())
  {
   //Subscribe to Ad event
   r.Show();
   r.OnAdRewarded += HandleRewardBasedVideoRewarded;
  }
 }

 public void HandleRewardBasedVideoRewarded(object sender, Reward args)
 {

  PlayerPrefs.SetInt("coins", PlayerPrefs.GetInt("coins") + 5);
  GameObject.FindGameObjectWithTag("Coins").GetComponent<Text>().text = PlayerPrefs.GetInt("coins").ToString();
  GameObject.FindGameObjectWithTag("Double").GetComponent<Button>().interactable = false;

  Debug.Log("Pref: " + PlayerPrefs.GetInt("coins"));
 }

 static void showInterstitial(InterstitialAd i)
 {
  if (i.IsLoaded())
  {
   i.Show();
  }
 }
}

I am rewarding players with 5 coins , But when I click button nothing appears , I have tried to change code in many ways but no positive result.

when i click in the button in unity the console show me "Dummy is loaded" and "Dummy showrewardedbasedvideoad"

Method that is called upon button click is ShowAd(). Please Help

1 Answers1

0
  1. Please check by adding debug in HandleRewardBasedVideoRewarded method to check if it's called.

  2. Also check you have added listener for that as you have not mentioned this in your code mentioned above.

    rewardBasedVideo.OnAdRewarded += this.HandleRewardBasedVideoRewarded;

  3. You have not initialised mobileAds with your app id:

    MobileAds.Initialize();

Community
  • 1
  • 1
Shweta
  • 231
  • 1
  • 13