Version: 2021.2
public static bool isPlaying ;

描述

在任何类型的已构建播放器中调用时,或者在播放模式的编辑器中调用时,返回 true(只读)。

在已构建播放器中,此方法将始终返回 true。

在编辑器中,如果编辑器处于播放模式,将返回 true。

Note: In the Editor for ScriptableObject assets, this property will return false in OnEnable. After reloading the domain, when reloading assemblies, Unity invokes OnEnable on all ScriptableObject instances. This happens before isPlaying is set to true.

另请参阅:Application.IsPlayingExecuteAlways

using UnityEngine;

class Example : MonoBehaviour { void Start() { if (Application.isPlaying) { print("In player or playmode"); } } }