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

时间:2016-03-16 02:51:19

标签: c# unity3d ads

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

我对C#FYI非常陌生。

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");
        }


    }
}
}

1 个答案:

答案 0 :(得分:0)

每个框架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 ,广告将再次显示