player controls menu

Hi everyone,

I want to create a menu that lists the controls for the player character. That is, keys and the actions they’re bound to. How should I proceed?

Thanks for your patience.

Depending on the design of your game, you can put the key binding information in a specific class or as a static class variable.

public class GameKey {
   public static KeyCode Left = KeyCode.A;
   public static KeyCode Right = KeyCode.D;

To use them:

if( Input.GetKey( GameKey.Left ) ) {
   //Move your character left

To do the binding, there are different ways to do it.

  1. Standard form: a label and a textfield, update the key binding whenever there are changes.
  2. Press a key: a set of buttons, when a button is press, prompt the user for input, the input is set as the key.
  3. Other ways that I did not think of as of this writing

So I will leave that to you to figure it out.

void OnGUI() {
   //Standard form
   inputString = GUILayout.TextField (...);
   GameKey.Left = Enum.Parse(typeof(KeyCode), inputString ); //Convert string to enum

   //Press a key form
   .... //Some kind of prompt
   GameKey.Left = e.KeyCode; //e is the Event.Current;

You will also need to save the key binding and load them (this also means that you will load the GameKey data using a function on the game start). This is a topic I am not familiar with, but I do think that it is doable using PlayerPrefs.