【问题标题】:Unity Rewarded Interstitial with Google Mobile Ads v6.0.2 - code from tutorial doesn't workUnity Rewarded Interstitial with Google Mobile Ads v6.0.2 - 教程中的代码不起作用
【发布时间】:2021-10-17 22:52:51
【问题描述】:

我正在尝试在 Unity 中向我的游戏添加广告,但不幸的是,使用官方 google 指南 (developers.google.com/admob/unity/rewarded-interstitial) 中的示例,我收到错误消息。谁能帮我解决这个问题?

public void Start()
{
    string adUnitId;
    #if UNITY_ANDROID
    adUnitId = trueRewardedAdId;
    #elif UNITY_EDITOR
    adUnitId = fakeRewardedAdId;
    #else
    adUnitId = "unexpected_platform";
    #endif

    // Create an empty ad request.
    AdRequest request = new AdRequest.Builder().Build();
    // Load the rewarded ad with the request.
    // Create an interstitial.
    RewardedInterstitialAd.LoadAd(adUnitId, request, AdLoadCallback);
}

private void AdLoadCallback(RewardedInterstitialAd ad, string error)
{
    if (error == null)
    {
        rewardedInterstitialAd = ad;

        rewardedInterstitialAd.OnAdFailedToPresentFullScreenContent += HandleAdFailedToPresent;
        rewardedInterstitialAd.OnAdDidPresentFullScreenContent += HandleAdDidPresent;
        rewardedInterstitialAd.OnAdDidDismissFullScreenContent += HandleAdDidDismiss;
        rewardedInterstitialAd.OnPaidEvent += HandlePaidEvent;
    }
}

【问题讨论】:

  • 我不使用激励广告,但我使用 Unity,我告诉你,在 6.0.0、6.0.1 和 6.0.2 版本中有几个错误。试试目前最稳定的5.4.0

标签: unity3d admob ads interstitial googlemobileads


【解决方案1】:

更新 LoadAd() 以使用操作作为参数,并在回调中将参数“错误”类型从字符串更改为 AdFailedToLoadEventArgs。

public void Start()
{
   ...
    RewardedInterstitialAd.LoadAd(adUnitId, request, (req,err) => 
adLoadCallback(req, err));
}

private void AdLoadCallback(RewardedInterstitialAd ad, AdFailedToLoadEventArgs error)
{
  ...
}

【讨论】:

    猜你喜欢
    • 2022-10-24
    • 1970-01-01
    • 2022-10-17
    • 1970-01-01
    • 2012-02-19
    • 1970-01-01
    • 2023-03-28
    • 2012-12-28
    • 1970-01-01
    相关资源
    最近更新 更多