整合admob奖励视频统一

时间:2018-05-06 17:25:41

标签: c# unity3d admob rewardedvideoad admob-rewardedvideoad

我试图整合广告,但问题是奖励广告没有显示。但是插页式广告确实有用。该场景等待2,3秒并显示插页式广告但不显示奖励广告,即使在日志中它确实显示"显示广告XXX"。

以下是游戏内容:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Gamescript: MonoBehaviour {

    public static bool isGameover;

    // Use this for initialization
    void Start() {
        isGameover = false;
        Invoke("GameOver", 2);
    }

    // Update is called once per frame
    void Update() {

    }

    void GameOver() {
        isGameover = true;
        Debug.Log("Game Over");
    }
}

这是我的奖励广告脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;

public class Newreward: MonoBehaviour {

    private RewardBasedVideoAd rewardBasedVideo;
    bool hasShownAdOneTime;

    // Use this for initialization
    void Start() {
        rewardBasedVideo = RewardBasedVideoAd.Instance;

        // Called when the user should be rewarded for watching a video.
        rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
        // Called when the ad is closed.
        rewardBasedVideo.OnAdClosed += HandleRewardBasedVideoClosed;
        LoadRewardBasedAd();

    }

    // Update is called once per frame
    void Update() {
        if (Gamescript.isGameover) {
            if (!hasShownAdOneTime) {
                hasShownAdOneTime = true;
                Invoke("ShowRewardBasedAd", 3);
            }
        }
    }

    public void LoadRewardBasedAd() {
        #if UNITY_EDITOR
        string adUnitId = "unused";
        #elif UNITY_ANDROID
        string adUnitId = "ca-app-pub-3940256099942544/5224354917";
        #elif UNITY_IPHONE
        string adUnitId = "ca-app-pub-3940256099942544/1712485313";
        #else
            string adUnitId = "unexpected_platform";
        #endif

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

    public void ShowRewardBasedAd() {
        if (rewardBasedVideo.IsLoaded()) {
            rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
            rewardBasedVideo.Show();

            Debug.Log("SHOW AD XXX");
        } else {
            MonoBehaviour.print("Dude no ad");
        }
    }

    public void HandleRewardBasedVideoClosed(object sender, System.EventArgs args) {
        this.LoadRewardBasedAd();
    }

    public void HandleRewardBasedVideoRewarded(object sender, Reward args) {
        string type = args.Type;
        double amount = args.Amount;
        MonoBehaviour.print("HandleRewardBasedVideoRewarded event received for " + amount.ToString() + " " + type);
    }
}

任何帮助将不胜感激

0 个答案:

没有答案