我会在一秒钟之后做出的表情......怎么样

时间:2017-08-26 23:56:19

标签: c# unity3d admob

这是我的代码,我会像几秒钟后出现的那样,不仅在Gameover中,我的应用程序中没有游戏功能。我会喜欢插页式广告。

我的代码已关闭,如果我启动应用并快速点击音板,则不会显示插页式广告。

using GoogleMobileAds.Api;
using UnityEngine;

public class GameScript : MonoBehaviour {
bool hasShownAdOneTime;

// Use this for initialization
void Start()
{
    //Request Ad
    RequestInterstitialAds();
}

void Update()
{
    //if (GameScript.isGameOver)
    {
        if (!hasShownAdOneTime)
        {
            hasShownAdOneTime = true;
            Invoke("showInterstitialAd", 2.0f);
        }
    }
}

public void showInterstitialAd()
{
    //Show Ad
    if (interstitial.IsLoaded())
    {
        interstitial.Show();

        //Stop Sound
        //

        Debug.Log("SHOW AD XXX");
    }

}

InterstitialAd interstitial;
private void RequestInterstitialAds()
{
    string adID = "";

    #if UNITY_ANDROID
    string adUnitId = adID;
    #elif UNITY_IOS
    string adUnitId = adID;
    #else
    string adUnitId = adID;
    #endif

    // Initialize an InterstitialAd.
    interstitial = new InterstitialAd(adUnitId);

    //***Test***
    // AdRequest request = new AdRequest.Builder()
    // .AddTestDevice(AdRequest.TestDeviceSimulator)       // Simulator.
    //.AddTestDevice("2077ef9a63d2b398840261c8221a0c9b")  // My test device.
    //  .Build();

    //***Production***
    AdRequest request = new AdRequest.Builder().Build();

    //Register Ad Close Event
    //interstitial.OnAdClosed += Interstitial_OnAdClosed;

    // Load the interstitial with the request.
    interstitial.LoadAd(request);

    Debug.Log("AD LOADED XXX");

    }

    //Ad Close Event
    //private void Interstitial_OnAdClosed(object sender, System.EventArgs e)
    //{
    //Resume Play Sound

    }

1 个答案:

答案 0 :(得分:0)

加载广告需要一些时间(视频广告需要10-60秒)。所以,如果你太早显示它,它将无法加载。确保interstitial.IsLoaded()返回true。