Unity Rewarded Interstitial with Google Mobile Ads v6.0.2 - 教程中的代码不起作用

Posted

技术标签:

【中文标题】Unity Rewarded Interstitial with Google Mobile Ads v6.0.2 - 教程中的代码不起作用【英文标题】:Unity Rewarded Interstitial with Google Mobile Ads v6.0.2 - code from tutorial doesn't work 【发布时间】: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 【参考方案1】:

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

public void Start()

   ...
    RewardedInterstitialAd.LoadAd(adUnitId, request, (req,err) => 
adLoadCallback(req, err));


private void AdLoadCallback(RewardedInterstitialAd ad, AdFailedToLoadEventArgs error)

  ...

【讨论】:

以上是关于Unity Rewarded Interstitial with Google Mobile Ads v6.0.2 - 教程中的代码不起作用的主要内容,如果未能解决你的问题,请参考以下文章

groovy 获取当前数据类型

unity怎么保存 unity保存的教程

unity怎么unity判断动画结束

unity和unity3D的区别

Unity3D资源文件 ③ ( Unity 资源包简介 | 导出 Unity 资源包 | 导出资源包的包含依赖选项 | 导入 Unity 资源包 | Unity 资源商店 )

Unity前景如何?现在unity还能找到工作吗?