Unity 广告永无止境。他们循环

Unity ads Never End. They Loop

您好,我的 unity 广告正在运行,但是当我点击关闭按钮时它不会停止,它只会加载另一个广告。我怎样才能让它在一个广告后停止播放并继续加载菜单?

我对 C# 非常陌生,仅供参考。

using UnityEngine;
using System.Collections;
using UnityEngine.Advertisements;

//GameOver page when the plane is destroyed
public class GameOverPage : MonoBehaviour {

public GUISkin skin; //skin for button styles
public static int start; //static integer indicates to show or hide Start/GameOver page
public static bool running; //static variable indicates if the plane is destroyed or not


void OnGUI(){
            GUI.skin = skin;

            //if start is not equal to 0 and running is false then show GameOver page buttons
            if ((StartPage.start != 0) && !PlaneMovement.running) {
        if (Advertisement.IsReady ()) {
            Advertisement.Show ();

        }



        if (GUI.Button (new Rect (Screen.width / 2.378f, Screen.height / 1.34f, Screen.width / 6f, Screen.height / 10.10f), "", skin.GetStyle ("Restart"))) {  
                            Application.LoadLevel (1);  
                            PlaneMovement.running = true;
                    }
        if (GUI.Button (new Rect (Screen.width / 1.50f, Screen.height / 1.34f, Screen.width / 6.0f, Screen.height / 10.1f), "", skin.GetStyle ("Home"))) {
                            Application.LoadLevel (0);  
                            PlaneMovement.running = false;
                            StartPage.start = 0;
                    }
        if (GUI.Button (new Rect (Screen.width / 5.7f, Screen.height / 1.34f, Screen.width / 6f, Screen.height / 10.10f), "", skin.GetStyle ("Website"))) {
                            Application.OpenURL ("http://www.skyboxertech.weebly.com");
                    }


        }
    }
}

编辑: 这就是我所拥有的。我不确定如何实现计时器,它会再次循环显示所有广告,并且不会将它们限制为每 5 次。

using UnityEngine;
using System.Collections;
using UnityEngine.Advertisements;

//GameOver page when the plane is destroyed
using UnityEngine.SceneManagement;


public class GameOverPage : MonoBehaviour {

public GUISkin skin; //skin for button styles
public static int start; //static integer indicates to show or hide
bool showAd = true; 
public static bool running; //static variable indicates if the plane is destroyed or not
public int gameOverCounter = 0; 

void OnGUI(){
    GUI.skin = skin;

    //if start is not equal to 0 and running is false then show GameOver page buttons
    if ((StartPage.start != 0) && !PlaneMovement.running) {
        gameOverCounter++;

        if (gameOverCounter >= 5) {
            showAd = true;
        if(showAd){ //Check if we should show add 
            if (Advertisement.IsReady ()) {
                Advertisement.Show ();
                showAd = false; 
                    gameOverCounter = 0;
                }
            }
        }

        if (GUI.Button (new Rect (Screen.width / 2.378f, Screen.height / 1.34f, Screen.width / 6f, Screen.height / 10.10f), "", skin.GetStyle ("Restart"))) {  
            SceneManager.LoadScene (1);  

            PlaneMovement.running = true;
        }
        if (GUI.Button (new Rect (Screen.width / 1.50f, Screen.height / 1.34f, Screen.width / 6.0f, Screen.height / 10.1f), "", skin.GetStyle ("Home"))) {
            SceneManager.LoadScene (0);  
            PlaneMovement.running = false;
            StartPage.start = 0;
        }
        if (GUI.Button (new Rect (Screen.width / 5.7f, Screen.height / 1.34f, Screen.width / 6f, Screen.height / 10.10f), "", skin.GetStyle ("Website"))) {
            Application.OpenURL ("http://www.skyboxertech.weebly.com");
        }


    }
}
}

OnGUI() 函数每 被调用 几次 次。只要StartPage.start不是0并且PlaneMovement.running不是 您的添加将始终显示。这两个条件满足。这就是广告 展示 的原因。我不知道这些变量是什么,也不知道你用它们做什么,但最好每 5 次 游戏结束而不是每次 展示你的广告游戏开启。它烦人,会让玩家删除你的游戏。

您可以创建一个名为 showAdd 的布尔变量来确定何时显示广告。下面的代码将显示一次广告。

using UnityEngine;
using System.Collections;
using UnityEngine.Advertisements;

//GameOver page when the plane is destroyed
public class GameOverPage : MonoBehaviour {

public GUISkin skin; //skin for button styles
public static int start; //static integer indicates to show or hide
bool showAd = true; //Will show ad the first time
public static bool running; //static variable indicates if the plane is destroyed or not


void OnGUI(){
            GUI.skin = skin;

            //if start is not equal to 0 and running is false then show GameOver page buttons
        if ((StartPage.start != 0) && !PlaneMovement.running) {
          if(showAd){ //Check if we should show add           
            if (Advertisement.IsReady ()) {
            Advertisement.Show ();
            showAd = false; //Set to false So that we dont show ad again
          }
      }


        if (GUI.Button (new Rect (Screen.width / 2.378f, Screen.height / 1.34f, Screen.width / 6f, Screen.height / 10.10f), "", skin.GetStyle ("Restart"))) {  
                            Application.LoadLevel (1);  
                            PlaneMovement.running = true;
                    }
        if (GUI.Button (new Rect (Screen.width / 1.50f, Screen.height / 1.34f, Screen.width / 6.0f, Screen.height / 10.1f), "", skin.GetStyle ("Home"))) {
                            Application.LoadLevel (0);  
                            PlaneMovement.running = false;
                            StartPage.start = 0;
                    }
        if (GUI.Button (new Rect (Screen.width / 5.7f, Screen.height / 1.34f, Screen.width / 6f, Screen.height / 10.10f), "", skin.GetStyle ("Website"))) {
                            Application.OpenURL ("http://www.skyboxertech.weebly.com");
                    }


        }
    }
}

然后你可以有一个整数变量计算游戏多少次超过。如果达到 5,请将 showAdd 设置为 true,广告将再次 show