这个问题最近困扰了我,以前从未注意到它,显然,我在我的 Unity3D 项目中使用了 admob 奖励视频。
在我的项目中,我奖励关卡失败的用户,当用户观看奖励视频时,会给予用户奖励,并且场景会自动更改为关卡选择。当用户再次开始游戏时,再次观看视频失败,但没有任何反应。
经过一些调试后,我发现第二次加载游戏场景时侦听器无法正常工作。
我有一个 GamePlayManager 脚本,我在其中执行所有功能..
public class GamePlayManager : MonoBehaviour {
private RewardBasedVideoAd rewardBasedVideoAd;
void Start()
{
rewardBasedVideoAd = RewardBasedVideoAd.Instance;
RequestRewardBasedVideo ();
rewardBasedVideoAd.OnAdFailedToLoad += HandleRewardBasedVideoFailedToLoad;
// has rewarded the user.
rewardBasedVideoAd.OnAdRewarded += HandleRewardBasedVideoRewarded;
}
private void RequestRewardBasedVideo()
{
#if UNITY_ANDROID
string adUnitId = GameConstants.AdmobRewardedVideoID;
#elif UNITY_IPHONE
string adUnitId = GameConstants.AdmobIOSRewardedVideoID;
#else
string adUnitId = "unexpected_platform";
#endif
AdRequest request = new AdRequest.Builder().Build();
rewardBasedVideoAd.LoadAd(request, adUnitId);
}
public void showAdmobRewardedVideo()
{
if (rewardBasedVideoAd.IsLoaded())
{
rewardBasedVideoAd.Show();
}
}
public void HandleRewardBasedVideoRewarded(object sender, Reward args)
{
Debug.Log ("Unity AdmobRewardGiven");
nextLevel ();
gotoLevelSelection ();
}
public void HandleRewardBasedVideoFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
Debug.Log ("Admob RewardedVideo FailedToLoad");
}
}