- Home /
Why won't my if result to true?
Please help me understand what I am doing wrong.
This
Event.current.keyCode == KeyCode.Return && Event.current.type == EventType.keyDown
results to true when I hit enter both outside and inside my TextArea
And this GUI.GetNameOfFocusedControl() == "textField"
results to true when I focus on my textArea Set to "textField"
but when I do this
(Event.current.keyCode == KeyCode.Return && Event.current.type == EventType.keyDown && GUI.GetNameOfFocusedControl() == "textField")
Nothing... Never gets set to true when I hit enter in my textField. I don't understand.
Answer by tanoshimi · Aug 10, 2014 at 06:36 PM
When you hit enter on a textfield, the event has already been "used" by the control by the time it gets to OnGUI, so instead of getting a keyDown event, you'll get a used event instead.
Try changing your code to:
if (Event.current.keyCode == KeyCode.Return && Event.current.type == EventType.used && GUI.GetNameOfFocusedControl() == "textField")
...
Thank you so much. I did not know about EvetType of used. Thanks!
Your answer
Follow this Question
Related Questions
Boolean problem!! 2 Answers
Engine Only Returns Responses for False 2 Answers
Boolean problem. 1 Answer
Boolean Uncheck Inspector if False 2 Answers