Привет, мои объявления единства работают, но не останавливаются, когда я нажимаю кнопку закрытия, она просто загружает другое объявление. Как я могу сделать это, чтобы он прекратил играть после одного объявления и продолжал загружать меню?Объявления Unity Never End. Они Loop
Я ОЧЕНЬ новичок в 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");
}
}
}
}
EDIT: Это то, что я имею. Я не уверен, как реализовать таймер, он снова отображает все объявления в цикле и не ограничивает их каждый пятый раз.
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");
}
}
}
}
как бы реализовать целочисленную переменную –
Вернитесь, когда вы напишете свою первую игру, и я предоставлю это. Сейчас я попытаюсь объяснить. Создайте переменную переменную, называемую gameOverCounter, и инициализируйте ее до 0. Когда игра закончена, увеличьте gameOverCounter на 1, выполнив gameOverCounter ++ или gameOverCounter = gameOverCounter + 1. Затем используйте инструкцию if, чтобы проверить, имеет ли gameOverCounter> = 5. Если это так, перезагрузите gameOverCounter до нуля, а затем включите объявление, установив showAd в true. После отображения объявления установите для showAd значение false, чтобы оно не отображалось снова. Это должно происходить снова и снова. Надеюсь, я объяснил это хорошо. – Programmer
Ive отредактировал мой оригинал с новым кодом –