Unity 3D和Admob“interstitial'在当前上下文中不存在

时间:2015-08-13 20:21:39

标签: c# unity3d admob

我第一次使用Unity 3D,所以我有点困惑。我的工作是在游戏中集成Google Admob广告。我成功整合了横幅广告,但我对插页式广告有疑问。在构建项目时,我收到此错误

  

Assets / scripts / gameScript.cs(85,29):错误CS0103:名称`interstitial'在当前上下文中不存在

这是我的代码的一部分:

using UnityEngine;
using System.Collections;
using GoogleMobileAds.Api;
[RequireComponent(typeof(AudioSource))]

public class gameScript : MonoBehaviour {

public int round, points, player, record;
public int balls, max_balls, combo;
public bool sfx, music, multi, new_record, power;
public AudioClip net, rim_hit, rim_hit2, ground, ground2;
public float sfxV = 1.0f, musicV = 1.0f;

public string username;
public string[] achvNames, score_names = new string[10];
public int[][] achv;
public int[] mpoints;
public double[] score_points = new double[10];

void Awake() {
    DontDestroyOnLoad(this.gameObject); 
    Screen.sleepTimeout = (int)SleepTimeout.NeverSleep;
    Time.timeScale = 1.0f;
}

void Start () {
    if(!PlayerPrefs.HasKey("achivmentInfo1"))
        gameObject.GetComponent<aManager>().reSetAchivments();
    Reset();
    Load ();
    AutoFade.LoadLevel(1,0.5f,0.5f,Color.black);

    #if UNITY_ANDROID
    string adUnitId = "xxx";
    #elif UNITY_IPHONE
    string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
    #else
    string adUnitId = "unexpected_platform";
    #endif

    // Create a 320x50 banner at the top of the screen.
    BannerView bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Bottom);
    // Create an empty ad request.
    AdRequest request = new AdRequest.Builder().Build();
    // Load the banner with the request.
    bannerView.LoadAd(request);

    #if UNITY_ANDROID
    string adUnitId2 = "xxx";
    #elif UNITY_IPHONE
    string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
    #else
    string adUnitId = "unexpected_platform";
    #endif

    // Initialize an InterstitialAd.
    InterstitialAd interstitial = new InterstitialAd(adUnitId2);
    // Create an empty ad request.
    AdRequest request2 = new AdRequest.Builder().Build();
    // Load the interstitial with the request.
    interstitial.LoadAd(request2);
}

//scoreScript callbacks
public void FinishRound(int lpoints, int lcombo, int lballs){
    if(!multi)
        points += lpoints;
    else
        mpoints[player] += lpoints;

    combo = lcombo;
    balls = lballs;

    if(points > record){
        new_record = true;
        record = points;
        Save();
    }
    if(balls > 0)
        GameObject.Find("round_menu").GetComponent<roundEnd>().Set(lpoints, points, record, false, multi, mpoints, player);
    else{
        GameObject.Find("round_menu").GetComponent<roundEnd>().Set(lpoints, points, record, true, multi, mpoints, player);              
        GameObject.Find("ChartBoostManager").GetComponent<CBads>().ShowAd("game_over");

        if (interstitial.IsLoaded()) {
            interstitial.Show();
        }

    }

0 个答案:

没有答案