Version: 2021.2
public static void Quit ();

参数

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

描述

退出播放器应用程序。

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

如果在其他应用程序中运行 Unity 时要使用 Application.Quit,请参阅 UnityasaLibrary-Android 将 Unity 作为库使用 手册页面以了解更多信息。

Note: In most cases termination of application under iOS should be left at the user's discretion. Calling this method in iOS player might appear to the user that the application has crashed. For more information, see Apple Technical Page qa1561.

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