Admob unity奖励视频不起作用

时间:2016-12-29 17:49:05

标签: android unity3d admob ads rewardedvideoad

我在我的Android游戏中使用Unity广告,一切都运行得很好,除了一些Unity广告有时没有展示的设备。所以,我想测试Admob奖励视频,看看我能否获得更好的表现。这是我用于Admob的代码:

 public void RequestRewardBasedVideo()
    {
#if UNITY_EDITOR
        string adUnitId = "unused";
#elif UNITY_ANDROID
        string adUnitId = "ca-app-pub-243186545632812xxxxxxxxxxxx";
#elif UNITY_IPHONE
        string adUnitId = "unused";
#else
        string adUnitId = "unexpected_platform";
#endif

        RewardBasedVideoAd rewardBasedVideo = RewardBasedVideoAd.Instance;

        AdRequest request = new AdRequest.Builder().Build();
        rewardBasedVideo.LoadAd(request, adUnitId);
        showAdvertisment(rewardBasedVideo);
    }

    private void showAdvertisment(RewardBasedVideoAd rewardBasedVideo)
    {
        if (rewardBasedVideo.IsLoaded())
        {

            rewardBasedVideo.Show();
            rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
        }


    }
    public void HandleRewardBasedVideoRewarded(object sender, Reward args)
    {
        //reward 
    }

我将RequestRewardBasedVideo()分配给按钮,但问题是视频没有显示!我想我是在正确的道路上,因为当我点击按钮时,控制台会记录:

Dummy .ctor
Dummy CreateRewardBasedVideoAd
Dummy LoadAd
Dummy IsLoaded
Dummy ShowRewardBasedVideoAd

我已经尝试将该应用程序放在我的Android设备上并导入了针对Unity的Google Admob软件包,并在Admob面板中配置了广告。任何人都有任何想法,我可以做些什么来解决这个问题?

3 个答案:

答案 0 :(得分:0)

这可能是由于目前没有奖励视频或没有广告视频。尝试使用测试广告进行测试请在您的请求代码中包含测试设备ID,如下所示:

 AdRequest request = new AdRequest.Builder()
                         .AddTestDevice("34343")
                         .Build();

尝试使用示例ad UNIT Id。希望它有效。

答案 1 :(得分:0)

你的代码错了。您应该将请求广告和展示广告分为两个功能。在Start()函数中,您调用请求函数并显示广告功能应该挂在您的按钮上。这是因为当您申请广告时,需要一些时间才能为您提供广告。

答案 2 :(得分:0)

如果未加载视频怎么办?您需要处理这种情况,听加载事件,然后点击显示。

    if (rewardBasedVideo.IsLoaded())
        {

            rewardBasedVideo.Show();
            rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
        }else{
             rewardBasedVideo.OnAdLoaded += HandleVideoLoaded;
}



public void HandleVideoLoaded(object sender, Reward args)
{
     rewardBasedVideo.Show();
            rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
}


 public void HandleRewardBasedVideoRewarded(object sender, Reward args)
    {
       rewardBasedVideo.OnAdRewarded -= HandleRewardBasedVideoRewarded;
    }