Version: 2023.1
public static void Quit ();

参数

exitCode 播放器应用程序在 Windows、Mac 和 Linux 上终止时返回的可选退出代码。默认值为 0。

描述

退出播放器应用程序。

关闭正在运行的应用程序。编辑器中会忽略 Application.Quit 调用。

If you want to use Application.Quit when running Unity inside another application, refer to UnityasaLibrary-Android Unity as a Library.

Mobile platforms like Android and iOS have their own dedicated interfaces to hide and close applications, which might be the preferred way to close applications for some users. Therefore, it's recommended to not create your own way of shutting down with Application.Quit to prevent inconsistent user experience between your application and these platform interfaces. If you must programmatically quit an Android application, you can instead move the application to the background via Activity.moveTaskToBack. For more information, refer to Quit a Unity Android application.

using UnityEngine;
using System.Collections;

// Quits the player when the user hits escape

public class ExampleClass : MonoBehaviour { void Update() { if (Input.GetKey("escape")) { Application.Quit(); } } }