我正在Unity中开发一个Android应用。我将其设置为可让玩家观看不同奖金的广告。我可以将其与测试广告一起使用,然后看到测试广告弹出。但是实际上奖励玩家的事件处理程序似乎不起作用。这是我设置的。
public void RequestRewardAd()
{
string adUnitId;
#if UNITY_ANDROID
adUnitId = "ca-app-pub-3940256099942544/5224354917";
#elif UNITY_IPHONE
//adUnitId = "ca-app-pub-3940256099942544/1712485313";
#else
adUnitId = "unexpected_platform";
#endif
this.rewardedAd = new RewardedAd(adUnitId);
// Called when an ad request has successfully loaded.
this.rewardedAd.OnAdLoaded += HandleRewardedAdLoaded;
// Called when an ad request failed to load.
this.rewardedAd.OnAdFailedToLoad += HandleRewardedAdFailedToLoad;
// Called when an ad is shown.
this.rewardedAd.OnAdOpening += HandleRewardedAdOpening;
// Called when an ad request failed to show.
this.rewardedAd.OnAdFailedToShow += HandleRewardedAdFailedToShow;
// Called when the user should be rewarded for interacting with the ad.
this.rewardedAd.OnUserEarnedReward += HandleUserEarnedReward;
// Called when the ad is closed.
this.rewardedAd.OnAdClosed += HandleRewardedAdClosed;
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the rewarded ad with the request.
this.rewardedAd.LoadAd(request);
}
public void HandleRewardedAdLoaded(object sender, EventArgs args)
{
MonoBehaviour.print("HandleRewardedAdLoaded event received");
}
public void HandleRewardedAdFailedToLoad(object sender, AdErrorEventArgs args)
{
MonoBehaviour.print(
"HandleRewardedAdFailedToLoad event received with message: "
+ args.Message);
}
public void HandleRewardedAdOpening(object sender, EventArgs args)
{
MonoBehaviour.print("HandleRewardedAdOpening event received");
}
public void HandleRewardedAdFailedToShow(object sender, AdErrorEventArgs args)
{
MonoBehaviour.print(
"HandleRewardedAdFailedToShow event received with message: "
+ args.Message);
rewardadnumber = 0;
}
public void HandleRewardedAdClosed(object sender, EventArgs args)
{
MonoBehaviour.print("HandleRewardedAdClosed event received");
this.RequestRewardAd();
rewardadnumber = 0;
}
public void HandleUserEarnedReward(object sender, Reward args)
{
if(rewardadnumber == 1)
{
NGS.Coins += 5;
NGS.CoinsText.text = "" + NGS.Coins;
PlayerPrefs.SetInt("CoinsPref", NGS.Coins);
rewardadnumber = 0;
}
if(rewardadnumber == 2)
{
NGS.ExtraHeart = true;
NGS.ExtraHeartsadwatched();
NGS.Extraheartsbutton.SetActive(false);
NGS.extraheartbonuscountdown = 10;
PlayerPrefs.SetInt("Extraheartcountdownpref", NGS.extraheartbonuscountdown);
rewardadnumber = 0;
}
}
我使用this.RequestRewardAd();
开始加载广告,并调用添加按钮通过游戏按钮显示。这些按钮还将“奖励数”更改为一或两个。广告按预期显示。那个家伙走了,说他要开除回叫服务员:P。只是当我关闭游戏时,选择的任何奖励都无法通过。
我错过了什么吗?