- Home /
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.
Answer by Chronos-L · Apr 13, 2013 at 01:28 AM
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.
Standard form: a label and a textfield, update the key binding whenever there are changes.
Press a key: a set of buttons, when a button is press, prompt the user for input, the input is set as the key.
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
.
Your answer
Follow this Question
Related Questions
Is it possible to make a custom launcher? 1 Answer
Pivot point stays on previous selected object 0 Answers
dynamically creating MenuItem via an xml File 2 Answers
Paused Menu backdrop 1 Answer