- Home /
How do you check if unity is running in c#
I have a code in cutom editor and this code needs to be active if unity is running. For example.
Camera.main.SendMessage("iListen",viewPos);
When unity is not running it spits out an error "!IsPlayingOrAllowExecuteInEditMode ()"
This is why I need to add an if code; should look something like this -
if (UnityIsPlaying) Camera.main.SendMessage("iListen",viewPos); // P.S. this is an example and does not work.
Answer by joshpsawyer · May 03, 2014 at 01:39 PM
Use EditorApplication.isPlaying:
if (EditorApplication.isPlaying) {
Camera.main.SendMessage("iListen",viewPos);
}
Thanks, is there a difference from
if (EditorApplication.isPlaying)
and
if (Application.isPlaying)
and those looking for when not playing its
if (Application.isEditor)
EditorApplication.isPlaying is true when you're playing the game from the editor. I chose this one because you specifically said a custom editor script.
Application.isPlaying is true when the application is playing in ANY player - essentially, whenever the game is being run.
Application.isEditor is true if you're running the game from the Unity Editor, so...
EditorApplication.isPlaying == (Application.isPlaying && Application.isEditor)
also, when the application isn't playing, just check whether isPlaying == false.
Your answer
Follow this Question
Related Questions
Is Running/Playing flag? 2 Answers
How can I check if another android app is running? 0 Answers
Locking levels on a level map? 1 Answer
check if each element in string is true simultaneously? 1 Answer
Do Objects Collide? 0 Answers