横幅视图在当前上下文中不存在

时间:2019-04-26 12:50:39

标签: admob

大家好,你好吗? 我已经编写了用于为游戏创建Admob标语的脚本。 但是我遇到一个错误,提示“在当前上下文中不存在横幅视图”。

这是代码

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

public class CrearBanner : MonoBehaviour {

// Use this for initialization
public void Start () {
    #if UNITY_ANDROID
        string appId = "ca-app-pub-2703074771097768~1633912383";
     #elif UNITY_IPHONE
        string appId = "ca-app-pub-3940256099942544~1458002511";
    #else
        string appId = "unexpected_platform";
    #endif

    // Initialize the Google Mobile Ads SDK.
    MobileAds.Initialize(appId);

    this.RequestBanner();
}

private void RequestBanner() {

    #if UNITY_ANDROID
         string adUnitId = "ca-app-pub-2703074771097768/7670520278";
    #elif UNITY_IPHONE
        string adUnitId = "ca-app-pub-3940256099942544/2934735716";
    #else
        string adUnitId = "unexpected_platform";
    #endif

    // Create a 320x50 banner at the top of the screen.
    bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Top);

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

}

}

我希望有人可以帮助我,我已经按照Google Admob的说明进行操作,但是我遇到了此错误,谢谢!

0 个答案:

没有答案