名称`admob'在当前上下文中不存在 [英] The name `admob' does not exist in the current context

查看:76
本文介绍了名称`admob'在当前上下文中不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用UnityEngine;

使用System.Collections;



公共类菜单:MonoBehaviour {

<登记/>
私人常量字符串AD_UNIT_ID = YOUR_AD_UNIT_ID;

私人常量字符串INTERSTITIAL_ID = YOUR_AD_UNIT_ID;



私人静态Vector2 BUTTON_SIZE =新Vector2(100,50);



私人的Rect buttonPositionShowAds;

私人的Rect buttonPositionHideAds;

private Rect buttonPositionShowInterstitial;





void Start(){





buttonPositionShowAds = new Rect(

(Screen.width - BUTTON_SIZE.x)/ 2,

(Screen.height - BUTTON_SIZE.y )/ 2,

BUTTON_SIZE.x,BUTTON_SIZE.y);



buttonPositionHideAds = new Rect(

buttonPositionShowAds.x,buttonPositionShowAds.y + BUTTON_SIZE.y * 3/2,

buttonPositionShowAds.width,buttonPositionShowAds.height) ;



buttonPositionShowInterstitial =新的Rect(

buttonPositionHideAds.x,buttonPositionHideAds.y + BUTTON_SIZE.y * 3/2,

buttonPositionHideAds.width,buttonPositionHideAds.height);

}



void OnEnable(){



}



void OnDisable(){



}



void HandleAdLoaded(){

#if!UNITY_EDITOR

admob.ShowBanner();

#endif

}



void HandleInterstitialLoaded(){

#if!UNITY_EDITOR
admob.ShowInterstitial();

#endif

}



void OnGUI() {

if(GUI.Button(buttonPositionShowAds,Show Ads)){

#if!UNITY_EDITOR

admob.ShowBanner();

#endif

}



if(GUI.Button(buttonPositionHideAds,隐藏广告)){

#if!UNITY_EDITOR

admob.HideBanner();

#endif

}



if(GUI.Button(buttonPositionShowInterstitial, 显示间质性)){

#如果UNITY_EDITOR

admob.RequestInterstitial(!);

#ENDIF

}

}

}



我尝试了什么:



i试图编写admob global。

using UnityEngine;
using System.Collections;

public class Menu : MonoBehaviour {

private const string AD_UNIT_ID = "YOUR_AD_UNIT_ID";
private const string INTERSTITIAL_ID = "YOUR_AD_UNIT_ID";

private static Vector2 BUTTON_SIZE = new Vector2(100, 50);

private Rect buttonPositionShowAds;
private Rect buttonPositionHideAds;
private Rect buttonPositionShowInterstitial;


void Start() {


buttonPositionShowAds = new Rect(
(Screen.width - BUTTON_SIZE.x) / 2,
(Screen.height - BUTTON_SIZE.y) / 2,
BUTTON_SIZE.x, BUTTON_SIZE.y);

buttonPositionHideAds = new Rect(
buttonPositionShowAds.x, buttonPositionShowAds.y + BUTTON_SIZE.y * 3 / 2,
buttonPositionShowAds.width, buttonPositionShowAds.height);

buttonPositionShowInterstitial = new Rect(
buttonPositionHideAds.x, buttonPositionHideAds.y + BUTTON_SIZE.y * 3 / 2,
buttonPositionHideAds.width, buttonPositionHideAds.height);
}

void OnEnable() {

}

void OnDisable() {

}

void HandleAdLoaded() {
#if !UNITY_EDITOR
admob.ShowBanner();
#endif
}

void HandleInterstitialLoaded() {
#if !UNITY_EDITOR
admob.ShowInterstitial();
#endif
}

void OnGUI() {
if (GUI.Button(buttonPositionShowAds, "Show Ads")) {
#if !UNITY_EDITOR
admob.ShowBanner();
#endif
}

if (GUI.Button(buttonPositionHideAds, "Hide Ads")) {
#if !UNITY_EDITOR
admob.HideBanner();
#endif
}

if (GUI.Button(buttonPositionShowInterstitial, "Show Interstitial")) {
#if !UNITY_EDITOR
admob.RequestInterstitial();
#endif
}
}
}

What I have tried:

i tried to write admob global.

推荐答案

你没有声明 admob 根本 - 在该代码中对它的所有引用都是一个你未声明的实例的使用。

你需要在类定义的开头声明它,只需和你一样

You don't declare admob at all - all references to it in that code are uses of an instance, which you have not declared.
You need to declare it at the start of your class definition, just like you do
private Rect buttonPositionShowAds;

并创建一个实例等级供它参考!

And create an instance of the class for it to reference!


这篇关于名称`admob'在当前上下文中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆