Version: 2017.4
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Application.CancelQuit

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static method CancelQuit(): void;
public static void CancelQuit();

Description

Cancels quitting the application. This is useful for showing a splash screen at the end of a game.

This function only works in the player. IMPORTANT: This function has no effect on iPhone. Application can not prevent termination under iPhone OS.

// 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.gameObject); }

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 ExampleClass : MonoBehaviour { public float showSplashTimeout = 2.0F; private bool allowQuitting = false; void Awake() { DontDestroyOnLoad(.gameObject); } 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(); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961