The deal is simple: I’ve got a huuuuge script, which is meant to be ran in Play Mode only (NPC customizable script). BUT! I’ve got a variable (boolean) “ShowHelp” - when you change it to True, a Debug.Log with user manual should pop up in the console, informing the User of what does this script do.
So in practice - all the script executed only in Play Mode, one function (showing this one Debug info) executing in Edit Mode.
How can this be arranged?
I’d say go with method suggested by @zeppike.
but if you can not and you really want to achieve it then here is a workaround:
- Set your script to ExecuteInEditMode.
- Have all your code except the function that should run in edit mode wrapped inside Application.isPlaying so that it will execute only when it is in play mode.
- And put your code from required function inside if(!Application.isPlaying) so that it will only execute in edit mode and not while game is running.
- You can even wrap your function inside #if UNITY_EDITOR … #endif
All the answers and comments were ultra-helpful! I’ll check out the Menu Item, as it may prove very useful!