- Home /
custom inspector and edit mode script
Hey guys,
I have created a new inspector which I want to use in combination with a script which is executed during edit mode (using [ExecuteInEditMode]).
The custom inspector is written like this:
float rotation = 0.0f;
public override void OnInspectorGUI() { rotation = EditorGUILayout.FloatField("Rotation:", rotation);
// do something useful
}
This works very well as long as I keep the gameobject selected. As soon as the gameobject looses focus and gets refocused, the rotation is set to 0, the initial value, again. Did I do something wrong, or is it just not possible?
Answer by rhodnius · Aug 03, 2012 at 07:33 PM
Hi DrahtMaul,
This is because the rotation variable has to be declared on the script derived from Monobehavior and not from the editor script it self. All variables declared in the editor script are "reset" when you deselect the gameobject that has the script derived from Monobehavior.
I would recommend to read the following articles that explain it in more detail:
http://docs.unity3d.com/Documentation/Components/gui-ExtendingEditor.html
http://active.tutsplus.com/tutorials/workflow/how-to-add-your-own-tools-to-unitys-editor/
Yeah, I figured that out myself already, I just forgot to say that here. I'm sorry about that. Thank you for the links anyways!