- Home /
Can I disable the use of Input.GetKey(KeyCode("any key")) while an InputField is in use?
In my game, I have a UI that can popup when you hit certain keys, such as I for inventory or M for map. I also have the occasional instance where I want the player to type things into an InputField. When I try to type in that InputField, it activates all those popups, for example if I tried to type "memory", the map would open and close while typing. Is there an easy way to disable this, or am I going to have to go back to all those popups and add an If statement that checks if there are any InputFields in use.
Answer by sbertuccio686 · Feb 18, 2020 at 11:45 AM
Not sure if there is an actual way to do this within unity but your best bet would be to create a bool such as isTyping, set it to true when you are using an input field and then in all the scripts that use Input.GetKey, do a check for isTyping too.
Answer by tormentoarmagedoom · Feb 18, 2020 at 02:20 AM
Hello.
In my opinion, you have 3 options:
1st: As you said, go back to all those popups and add an If statement that checks if there are any InputFields in use.
2nd (The more correct for the future) Go back, but add an if statement to a new static variable called like "ableToDo". All things involved in the ingame, like open the map, move the camera, move char.... Check if this new bool is true before execute. Then, all Canvas, menus, Inputfields that you want to prevent that gaming popups, changes "ableToDo" to false, so noone will be executed.
3rd Quicker but future disaster. In the new popups, do a code to disable the sccripts components like the map while is open.
Choose !
Good luck!!
Your answer
Follow this Question
Related Questions
How can I block Copy Paste from Input Field? 3 Answers
InputField null refrence exception 1 Answer
UI slider "End slide" event 3 Answers
Prevent focus from leaving inputfield 0 Answers
How do I get Input Fields to work with a controller? 0 Answers