我收到此错误:
Assets / initadmod.cs(25,2):错误CS0118:
Admob' is a
命名空间',但type' was expected
请将此脚本复制到您的MonoDevelop中,以查看错误所在。
using UnityEngine;
using System.Collections;
using Admob;
namespace Admob {
namespace GoogleMobileAds {
public class initadmod : MonoBehaviour {
public static initadmod instance;
// Use this for initialization
void Start () {
instance = this;
Debug.Log("start unity demo-------------");
initAdmob();
}
public string baner_Adr;
public string fullbaner_Adr;
public string baner_IOS ;
public string fullbaner_IOS ;
Admob ad;
//bool isAdmobInited = false;
void initAdmob()
{
string adUnitIdbaner ;
string adUnitIdfull ;
// isAdmobInited = true;
#if UNITY_EDITOR
adUnitIdbaner = "baner_Adr";
adUnitIdfull = "fullbaner_Adr";
#elif UNITY_ANDROID
adUnitIdbaner = baner_Adr;
adUnitIdfull = fullbaner_Adr;
#elif UNITY_5 || UNITY_IOS || UNITY_IPHONE
adUnitIdbaner = baner_IOS;
adUnitIdfull = fullbaner_IOS;
#else
adUnitIdbaner = baner_Adr;
adUnitIdfull = fullbaner_Adr;
#endif
ad = Admob.Instance();
ad.bannerEventHandler += onBannerEvent;
ad.interstitialEventHandler += onInterstitialEvent;
ad.rewardedVideoEventHandler += onRewardedVideoEvent;
ad.nativeBannerEventHandler += onNativeBannerEvent;
ad.initAdmob(adUnitIdbaner, adUnitIdfull);
// ad.setTesting(true);
Debug.Log("admob inited -------------");
}
public bool ShowBanerOnPlay;
public bool _ShowFullOnBackToMainMenu;
public bool _ShowFullNowOnOpenGame;
public int ShowFullOndie;
/// <summary>
/// hiện baner nhỏ góc trên màn hình lúc chạy
/// </summary>
public void ShowBanerOnPlayGame()
{
if (ShowBanerOnPlay)
{
ShowBaner();
}
}
/// <summary>
/// hiện baner lúc chết
/// sau Showfullondie số lần chết mới cho hiện
/// </summary>
public void ShowFullOnDie()
{
if (UImanager.uimanager.showbane >= ShowFullOndie-1)
{
showInterstitial();
UImanager.uimanager.showbane = 0;
}
}
/// <summary>
/// hiện qc khi đến menu chính
/// </summary>
public void ShowFullOnBackToMainMenu()
{
if (_ShowFullOnBackToMainMenu)
{
showInterstitial();
}
}
/// <summary>
/// hiện quảng cáo khi mới mở game ra khi hết mục dowload
/// </summary>
public void ShowFullNowOnOpenGame()
{
if (_ShowFullNowOnOpenGame)
{
showInterstitial();
}
}
void showInterstitial()
{
if (ad.isInterstitialReady())
{
ad.showInterstitial();
}
else
{
ad.loadInterstitial();
}
}
void ShowBaner()
{
Admob.Instance().showBannerRelative(AdSize.SmartBanner, AdPosition.TOP_CENTER, 0);
}
public void HideBaner()
{
Admob.Instance().removeBanner();
}
void onInterstitialEvent(string eventName, string msg)
{
Debug.Log("handler onAdmobEvent---" + eventName + " " + msg);
if (eventName == AdmobEvent.onAdLoaded)
{
Admob.Instance().showInterstitial();
}
}
void onBannerEvent(string eventName, string msg)
{
Debug.Log("handler onAdmobBannerEvent---" + eventName + " " + msg);
}
void onRewardedVideoEvent(string eventName, string msg)
{
Debug.Log("handler onRewardedVideoEvent---" + eventName + " " + msg);
}
void onNativeBannerEvent(string eventName, string msg)
{
Debug.Log("handler onAdmobNativeBannerEvent---" + eventName + " " + msg);
}
}
}
}
答案 0 :(得分:0)
您在第25行声明
Admob ad;
但是Admob是一个名称空间,而不是一个类,因此您需要将类添加到声明中,也许是这样的(这只是一个示例)
Admob.GoogleMobileAds.initadmod ad;