- Home /
Best Answer
Answer by Jamora · Mar 13, 2014 at 06:40 PM
You can intercept the press of the Play button. You just need to subscribe to EditorApplication.playmodeStateChanged.
So something like this:
[MenuItem("Edit/Play", true,1)]
static void func(){
EditorApplication.playmodeStateChanged += StateChange;
}
static void StateChange(){
Debug.Log("State Changed");
}
This event will be called both on starting and stopping playmode. If you need to perform actions on only a certain mode, you will need either EditorApplication.isPlayingOrWillChangePlaymode or EditorApplication.isPlaying
Did so:
[InitializeOnLoad]
class Tester : object{
static Tester(){
EditorApplication.playmodeStateChanged += PlayStateChanged;
}
static void PlayStateChanged(){
Debug.Log ("playmodeStateChanged");
}
}