Check ifspecifickey ispressed

Hello reader, how can i check if a custom key (ex “m” to open map) is pressed?

You can use GetKeyDown to test if a specific key is pressed:

You can also add “custom” keys to the InputManager, and then test for those by string. In Project Settings → Input, increment the Size value, and name your new key. In your code, test for that new key with Input.GetButton. For example, you want a map that can be toggled, so you’d create a new input named “Map” and gave it the key “m”. Then you can add this to your Update method:

if (Input.GetButton("Map")) {
  ...
}

and voila, the player types “m” and the map appears. The cool thing about this method is the player can remap the key at startup (and the player can see all the bound keys, too!).

It worked man, thank you :smiley: