Skip to content

Instantly share code, notes, and snippets.

@nastajus
Created June 14, 2014 21:44
Show Gist options
  • Save nastajus/311fa7bc191abe7c48db to your computer and use it in GitHub Desktop.
Save nastajus/311fa7bc191abe7c48db to your computer and use it in GitHub Desktop.
Was thinking of what data structure I'd procedurally populate the Input manager for Unity, came up with the following. But interestingly I first tried using enum Directions instead simply containing Up, Down, Left, and Right, but when I got to making the nested dictionary I realized that wouldn't help, that each player needs a **different** set …
public class PlayerControl : MonoBehaviour {
//...
private class Directions{
KeyCode Up;
KeyCode Down;
KeyCode Left;
KeyCode Right;
}
private Dictionary<Players, KeyCode> mapKeyboard = new Dictionary<Players, Directions>(){
{Players.player1, new Directions(KeyCode.W, KeyCode.S, KeyCode.A, KeyCode.D) },
{Players.player2, new Directions(KeyCode.UpArrow, KeyCode.DownArrow, KeyCode.LeftArrow, KeyCode.RightArrow) },
{Players.player3, new Directions(KeyCode.O, KeyCode.L, KeyCode.K, KeyCode.Colon) },
{Players.player4, new Directions(KeyCode.Keypad8, KeyCode.Keypad2, KeyCode.Keypad4, KeyCode.Keypad6) }
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment