Google AdMob广告未在Unity中展示

时间:2019-11-10 16:04:42

标签: android unity3d

我正在制作“飞扬的小鸟”游戏,并试图在小鸟死后显示广告。 我分别从Google AdMob控制台和Unity仪表板设置了Google AdMob和UnityAds。

这是我的下面的代码。

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

public class GameController : MonoBehaviour {
    public static GameController instance;
    public GameObject gameOverText;
    public bool isGameOver = false;
    public float scrollSpeed = -1.5f;
    public Text scoreText;
    private int score = 0;
    private InterstitialAd interstitialAd; 
    // Awake is called before Start
    void Awake() {
        if(instance == null) {
            instance = this;
        } else if (instance != null) {
            Destroy(gameObject);
        }
    }
    // Start is called before the first frame update
    void Start() {
        MobileAds.Initialize(initStatus => { });
        RequestInterstitial();
    }


    private void RequestInterstitial() {
        string adUnitId = "unexpected_platform";
#if UNITY_ANDROID
        adUnitId = Values.TEST_ANDROID_AD_UNIT_ID;
#endif
        // Initialize InterstitialAd
        this.interstitialAd = new InterstitialAd(adUnitId);
        // Create empty ad request
        AdRequest request = new AdRequest.Builder().Build();
        // Load interstitial with the request
        this.interstitialAd.LoadAd(request);
    }

    public void ShowAd() {
        if (this.interstitialAd.IsLoaded()) {
            this.interstitialAd.Show();
        }
    }

    // Update is called once per frame
    void Update() {
        if(isGameOver && Input.GetKey(KeyCode.Space)) {
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
        } else if (isGameOver && Input.touchCount > 0) {
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
        }
    }

    public void BirdScored() {
        if(isGameOver) {
            return;
        }
        score++;
        scoreText.text = "Score: " + score;
    }

    public void BirdDied() {
        gameOverText.SetActive(true);
        isGameOver = true;
        ShowAd();
    }
}

当我调试但代码未显示时,代码到达ShowAd()函数。

我在做什么错了?

0 个答案:

没有答案