- Home /
ExecuteInEditMode, Only parts of my code?
I'm trying to make a flash timeline exporter and I'd like my assets to automatically be placed once I attach the timeline XML to the component, right now I can make it come true with [ExecuteInEditMode], but the timeline is not paused so it plays automatically, and I don't want that, I want it to be frozen at the first frame (and eventually at any given frame), but at playtime I want it to play automatically.
Is there any way to make some code visible only in edit mode and some only in play mode, or any known easy workaround for that?
Answer by DaJuice · Oct 23, 2012 at 05:40 PM
Well, maybe I'll help one or two othere helpless persons out there with the same problem:
There is an attribute called Application.isPlaying that returns true if the script is run while playing and not in edit mode, and in order to be as efficient as possible, we can couple that with compilation variables, this gives:
#if UNITY_EDITOR
if (!Application.isPlaying) return //or whatever script needs to be run when in edition mode.
#endif