Cancels quitting the application. This is useful for showing a splash screen at the end of a game.
// Delays quitting for 2 seconds and
// loads the finalsplash level during that time. var showSplashTimeout : float = 2.0;
private var allowQuitting : boolean = false; function Awake () {
// This game object needs to survive multiple levels
DontDestroyOnLoad (this);
} function OnApplicationQuit () {
// If we haven't already load up the final splash screen level
if (Application.loadedLevelName.ToLower() != "finalsplash")
StartCoroutine("DelayedQuit"); // Don't allow the user to exit until we got permission in
if (!allowQuitting)
Application.CancelQuit();
} function DelayedQuit () {
Application.LoadLevel("finalsplash"); // Wait for showSplashTimeout
yield WaitForSeconds(showSplashTimeout); // then quit for real
allowQuitting = true;
Application.Quit();
}
using UnityEngine; using System.Collections; public class Example : MonoBehaviour { public float showSplashTimeout = 2.0F; private bool allowQuitting = false; void Awake() { DontDestroyOnLoad(); } void OnApplicationQuit() { if (Application.loadedLevelName.ToLower() != "finalsplash") StartCoroutine("DelayedQuit"); if (!allowQuitting) Application.CancelQuit(); } IEnumerator DelayedQuit() { Application.LoadLevel("finalsplash"); yield return new WaitForSeconds(showSplashTimeout); allowQuitting = true; Application.Quit(); } }
import UnityEngine import System.Collections public class Example(MonoBehaviour): public showSplashTimeout as float = 2.0F private allowQuitting as bool = false def Awake() as void: DontDestroyOnLoad(self) def OnApplicationQuit() as void: if Application.loadedLevelName.ToLower() != 'finalsplash': StartCoroutine('DelayedQuit') if not allowQuitting: Application.CancelQuit() def DelayedQuit() as IEnumerator: Application.LoadLevel('finalsplash') yield WaitForSeconds(showSplashTimeout) allowQuitting = true Application.Quit()