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();
		}
	}
}

我用5个硬币奖励玩家,但是当我点击按钮时什么都没有出现,我尝试了多种方式更改代码但没有积极的结果。

当我在统一中单击按钮时,控制台会显示“已加载虚拟”和“虚拟 showrewardedbasedvideoad”

单击按钮时调用的方法是 ShowAd()。请帮忙

4

1 回答 1

0
  1. 请通过在 HandleRewardBasedVideoRewarded 方法中添加调试来检查它是否被调用。

  2. 还要检查您是否为此添加了侦听器,因为您在上面提到的代码中没有提到这一点。

    rewardBasedVideo.OnAdRewarded += this.HandleRewardBasedVideoRewarded;

  3. 您尚未使用您的应用程序 ID 初始化 mobileAds:

    MobileAds.Initialize();

于 2018-07-02T09:23:36.373 回答