Version: 2022.1
言語: 日本語

説明

Sent to all GameObjects before the application quits.

In the Editor, Unity calls this message when playmode is stopped.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void OnApplicationQuit() { Debug.Log("Application ending after " + Time.time + " seconds"); } }

Note: iOS applications are usually suspended and do not quit. For iOS builds, enable the "Exit on Suspend" property in Player Settings to make the application quit and not suspend, otherwise you might not see this call. If you do not enable the "Exit on Suspend" property then you will see calls to OnApplicationPause instead.

On Windows Store Apps and Windows Phone 8.1 there is no application quit event. Use the OnApplicationFocus event when focusStatus equals false.
On WebGL it is not possible to implement OnApplicationQuit because of the way browser tabs close. For a workaround, see the Unity User Manual documentation on Interacting with browser scripting in WebGL.

Warning: If the user suspends your application on a mobile platform, the operating system can quit the application to free up resources. In this case, depending on the operating system, Unity might be unable to call this method. On mobile platforms, it is best practice to not rely on this method to save the state of your application. Instead, consider every loss of application focus as the exit of the application and use MonoBehaviour.OnApplicationFocus to save any data.

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961