受众网络非页内广告无效! Unity 3D

时间:2019-03-20 19:48:10

标签: c# unity3d facebook-audience-network

我用统一的3D制作了游戏,并向其中添加了Facebook受众网络插页式广告。

开始场景时,插页式广告已成功加载,但没有显示,我在控制台中收到此消息:

  

投放非页内广告

您能帮我解决这个问题吗?

GameManager脚本:

    using UnityEngine.SceneManagement;
    using AudienceNetwork;

public class GameManager : MonoBehaviour {

    private InterstitialAd interstitialAd;
    private bool isLoaded;
    bool shown = false;
    static int loadCount = 0;

    bool GameHasEnded = false;
    float NextLevelDelay = 1f;
    float RestartDelay = 2f;


    void Start () {

        this.LoadInterstitial();
    }

    public void ShowInterstitial()
    {
        if (this.isLoaded)
        {
            this.interstitialAd.Show();
            this.isLoaded = false;
            Debug.Log("Interstitial Shown");
        }
        else
        {
            Debug.Log("Interstitial Ad not loaded!");
        }
    }

    public void CompleteLevel()
    {
        Invoke("NextLevel", NextLevelDelay);
    }

    public void EndGame()
    {    
        if (GameHasEnded == false)
        {
            GameHasEnded = true;
            Invoke("Restart", RestartDelay);
        }
    }

    public void NextLevel()
    {
        if ((loadCount % 2) == 0)  // only show ad every third time
        {
            if (!shown)
            {
                ShowInterstitial();
                shown = true;
            }
        }
        SceneManager.LoadScene(SceneManager.GetActiveScene().path);
        loadCount = loadCount + 1;
    }

    void Restart()
    {
        if ((loadCount % 2) == 0)  // only show ad every third time
        {
            if (!shown)
            {
                ShowInterstitial();
                shown = true;
            }
        }
        SceneManager.LoadScene(SceneManager.GetActiveScene().path);
        loadCount = loadCount + 1;
    }

    public void LoadInterstitial()
    {
        this.interstitialAd = new InterstitialAd("DEMO_AD_TYPE#YOUR_PLACEMENT_ID");
        this.interstitialAd.Register(this.gameObject);

        // Set delegates to get notified on changes or when the user interacts with the ad.
        this.interstitialAd.InterstitialAdDidLoad = (delegate () {
            Debug.Log("Interstitial ad loaded.");
            this.isLoaded = true;
        });
        interstitialAd.InterstitialAdDidFailWithError = (delegate (string error) {
            Debug.Log("Interstitial ad failed to load with error: " + error);
        });
        interstitialAd.InterstitialAdWillLogImpression = (delegate () {
            Debug.Log("Interstitial ad logged impression.");
        });
        interstitialAd.InterstitialAdDidClick = (delegate () {
            Debug.Log("Interstitial ad clicked.");
        });

        this.interstitialAd.interstitialAdDidClose = (delegate () {
            Debug.Log("Interstitial ad did close.");
            if (this.interstitialAd != null)
            {
                this.interstitialAd.Dispose();
            }
        });

        // Initiate the request to load the ad.
        this.interstitialAd.LoadAd();
    }

}

0 个答案:

没有答案