试图声明“ Admob”以修复“名称“ Admob”在当前上下文中不存在”错误

时间:2019-07-10 14:41:47

标签: c# android unity3d admob

我正在尝试将Google Admob Ads集成到我的项目中,但是出现此错误“名称“ Admob”在当前上下文中不存在”。 我想我必须在脚本中声明“ Admob”……但是,由于我是新手,所以我不知道应该在脚本中添加什么来解决该问题。

using UnityEngine;
using GoogleMobileAds.Api;

public class AdManager : MonoBehaviour {

    public static AdManager instance;

    public const string bannerAndroidID = "ca-app-pub-3940256099942544/6300978111";
    public const string banneriOSID = "ca-app-pub-3940256099942544/6300978111";
    public const string interstitialAndroidID = "ca-app-pub-3940256099942544/1033173712";
    public const string interstitialiOSID = "ca-app-pub-3940256099942544/1033173712";

    void Awake(){

    }

    void MakeSingleton(){
        if (instance != null) {
            Destroy (gameObject);
        } else {
            instance = this;
            DontDestroyOnLoad (gameObject);
        }
    }

    void Start(){
        #if UNITY_ANDROID
        Admob.Instance().initAdmob(bannerAndroidID, interstitialAndroidID);
        Admob.Instance().loadInterstitial();
        #elif UNITY_IOS
        Admob.Instance().initAdmob(banneriOSID, interstitialiOSID);
        Admob.Instance().loadInterstitial();
        #endif
        ShowBanner ();
    }

    public void ShowBanner(){
        Admob.Instance ().showBannerRelative (AdSize.Banner, AdPosition.TOP_CENTER, 5);
    }

    public void ShowInterstitial(){
        if (Admob.Instance ().isInterstitialReady ()){
            Admob.Instance ().showInterstitial ();
        }
    }
}

0 个答案:

没有答案