- Home /
Question by
$$anonymous$$ · May 21, 2014 at 06:28 PM ·
editor
Check if a script is running in editor or game
Hi guys, quick question related to scripting: There is a way to understand if a script is running in editor or in the game? Basically my problem is that I have created a script which can be executed in editor more using the config
[ExecuteInEditMode]
And I've put some code into the OnRenderObject function. The problem is that I want that this code only runs in the editor and not when the game is running. There's a quick solution for that?
Thank you guys
Comment
Best Answer
Answer by $$anonymous$$ · May 21, 2014 at 07:42 PM
Ok, I've found that the best way to detect if the game is actually running is to check the property Application.isPlaying.
if(Application.isPlaying){
// The game is running
}
else {
// The script is executing inside the editor
}
Answer by MaT227 · May 23, 2014 at 08:48 AM
Is suggest you to use the Platform Defines. This will optimize a bit your app.