我有内部装有admob奖励广告的统一应用程序。每次用户启动应用程序时,请转到主界面并单击一个按钮,然后显示奖励广告。
广告展示后,它调用了一个事件HandleRewardBasedVideoRewarded
,但问题是,该事件只能调用一次,即使我转到另一个场景也不能再次调用该事件。回到主要场景。
在我重新启动应用程序后,它将再次调用该事件。
有什么办法解决吗?
谢谢
下面是我的源代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Android;
using GoogleMobileAds.Common;
using GoogleMobileAds.Api;
using System;
using UnityEngine.SceneManagement;
using DG.Tweening;
public class z_reward_ads : MonoBehaviour {
public string _rewardid = "...";
private RewardBasedVideoAd rewardBasedVideo;
private AdRequest rewardRequest;
public GameObject MANAGER_SCORE;
public GameObject BoxButton;
public GameObject textButton;
// Use this for initialization
void Start () {
this.rewardBasedVideo = RewardBasedVideoAd.Instance;
RequestRewardedAds ();
rewardBasedVideo.OnAdLoaded += HandleRewardBasedVideoLoaded;
rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
textButton.transform.DOPunchScale (new Vector3 (1, 1, 0), 2, 1, 0);
}
public void RequestRewardedAds()
{
// Create an empty ad request.
rewardRequest = new AdRequest.Builder()
.AddTestDevice("...")
.Build();
this.rewardBasedVideo.LoadAd(rewardRequest, _rewardid);
}
public void ShowRewardedAds()
{
if (rewardBasedVideo.IsLoaded()) {
rewardBasedVideo.Show();
}
}
//===REWARDED_VIDEO_EVENT
public void HandleRewardBasedVideoLoaded(object sender, EventArgs args)
{
BoxButton.SetActive (true);
}
public void HandleRewardBasedVideoRewarded(object sender, Reward args)
{
MANAGER_SCORE.GetComponent<z_global_score> ().AddScore (10);
Scene scene = SceneManager.GetActiveScene();
SceneManager.LoadScene (scene.name);
}
// Update is called once per frame
void Update () {
}
}