- Home /
Reliable / intelligent user input handling
I just started programming a completely new game. As there are no components yet, i've made up my mind how i could delegate / handle the user input depending on the current game state.
Let's imagine, that there will be some different components in my game, that will need user input: Inventory, chat window, console, user-movement, camera, menu and many more.
For Example, i want the camera only to rotate / translate if: the inventory is not opened. the menu is not opened * if the user has not pressed a specific keycode.
Is there a specific or good pattern to follow or to form my scripts? I'd like to avoid scripts like this:
if(_myGameController.MenuIsOpened && myGameController.InventoryIsOpened && !Input.GetKey(KeyCode.A))
{
// Yep, i should handle the user input
}
The problem with the code shown above would be that if i'm going to add a new state in a couple of weeks, i'd have to change all the other scripts that the state may influence.
I also thought of grouping keycodes together - for example "Moving-Keys", "Inventory Keys" and so on for disabling a whole group..
Thanks in advance!