Пример кода если игра была запущена из эдитора:
Returns true if the game is being run from the Unity editor; false if run from any deployment target.
Возвращает true, если запущен редактор Unity; false в остальных случаях
using UnityEngine;
class Example : MonoBehaviour
{
void Start()
{
if (Application.isEditor)
{
print("We are running this from inside of the editor!");
}
}
}
https://docs.unity3d.com/ScriptReference/Application-isEditor.html
Если игра запущена в принципе:
using UnityEngine;
class Example : MonoBehaviour
{
void Start()
{
if (Application.isPlaying)
{
print("In player or playmode");
}
}
}
https://docs.unity3d.com/ScriptReference/Application-isPlaying.html
Так же возможно будет полезным атрибут [ExecuteInEditMode]
[ExecuteInEditMode]
public class PrintAwake : MonoBehaviour
{
void Awake()
{
Debug.Log("Editor causes this Awake");
}
void Update()
{
Debug.Log("Editor causes this Update");
}
}
https://docs.unity3d.com/ScriptReference/ExecuteInEditMode.html