I have a question about how to make an “Options > Controls” screen like most games include. My game currently accepts a mouse, touch, keyboard, or joystick. Then the user can choose the controller s/he prefers and everything works fine, but I wish to allow him/her to tell which key on the keyboard or Joystick button s/he wants to perform each action.
I don’t know any way to do that! How to tell which key/joystick button the player has pressed, so I can update the control preferences in the game?
UPDATE:
It is really simple to rebind a key with that! While the video and Unity samples help a lot, I want to share this very simple code snippet I managed to work:
InputAction action = myPlayerInput.actions.FindAction("MyAction");
action.Disable();
var rebinder = action.PerformInteractiveRebinding(/* binding index to override */)
.OnComplete(operation => {
action.Enable();
Debug.Log("Rebind completed!");
operation.Dispose();
})
.OnCancel(operation => {
action.Enable();
Debug.Log("Rebind cancelled!");
operation.Dispose();
});
rebinder.Start();
Debug.Log("Waiting for input...");
*Notice it is a very very simplified snippet. For more complex examples, follow Rene-Damm link.