Version: 2018.2 (switch to 2018.3b or 2017.4)
LanguageEnglish
  • C#
Method group is Obsolete

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

Obsolete 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.

Note: CancelQuit has been deprecated. Please use Application.wantsToQuit instead.

Note: This function has no effect on iPhone. Application can not prevent termination under iPhone OS.

using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour { // Delays quitting for 2 seconds and // loads the finalsplash level during that time.

float showSplashTimeout = 2.0f; bool allowQuitting = false;

void Awake() { // This game object needs to survive multiple levels Application.DontDestroyOnLoad(this.gameObject); }

void 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(); } }

IEnumerator DelayedQuit() { Application.LoadLevel("finalsplash");

// Wait for showSplashTimeout yield return new WaitForSeconds(showSplashTimeout);

// then quit for real allowQuitting = true; Application.Quit(); } }

Did you find this page useful? Please give it a rating: