- Home /
How do I prevent value using EditorGUILayout.FloatField to not change as soon as I change the float field value ?
this is an example of what my code looks like . how do i make the value only change when i have clicked outside of the field after changing the value or only after pressing the enter key ?
int amount;
void OnGUI()
{
amount = (int)EditorGUILayout.FloatField("Number of types",amount, GUILayout.MaxWidth(200)));
}
Wrap line 5 in an if-clause for checking, if you pressed enter, or if you clicked somewhere. I'm not sure how to do the second one, but this might help in finding the answer
Answer by gameplay4all · Mar 25, 2015 at 06:19 PM
int amount;
int tempAmount;
void OnGUI()
{
tempAmount = (int)EditorGUILayout.FloatField("Number of types",tempAmount, GUILayout.MaxWidth(200)));
if( Event.current.type == EventType.KeyUp && Event.current.keyCode == KeyCode.Return){
{
amount = tempAmount;
}
}
I am not sure about using Input.GetKeyUp in OnGUI, I seem to vagely remember something about that :/
Good luck!
thanks , that would work too but i was hoping that unity had something in the API that handled that kind of process
it would be event not input when checking for enter key in the editor window
Evnet.current.Equals(Event.$$anonymous$$eyboardEvent("[enter]"))
Your answer
Follow this Question
Related Questions
Handling Undo/REdo in EditorWindow when editing DB record. 0 Answers
Script work in editor but not in build 0 Answers
Create Multiple Foldouts. 1 Answer