Home > Enterprise >  Keymapping in unity
Keymapping in unity

Time:10-11

I'm working on a game in unity. I have several things that are supposed to happen when a certain key is pressed, like w to move forward. The problem, is that some people might prefer a different key layout and different buttons for different actions. I saw lots of unity games where you're able to choose yourself your prefered keys, however I can't seem to find a explanaiton of how to do so. Is there a way of creating some kind of menu, where when you press on a certain action name, unity then, would record your input, and during the game check if that button is pressed?

CodePudding user response:

You can create your own script what wil handle it.Most easy way to save your keys to json for example and every time game load then this file is loaded.And when user change key binding then you save it to that file.

For example if you want change jump, then you select jump in your menu , let user press button he want and then save button he pressed to that file.So for jump will be used this button.

You can use this https://docs.unity3d.com/ScriptReference/Event-keyCode.html

  • Related