Skip to main content
added 157 characters in body
Source Link
Sidar
  • 3.6k
  • 2
  • 17
  • 28

Im not sure if this will work, I haven't actually tested it.

public abstract class InputControllerKeyInputController{ public char forward = 'w'; public char backward = 's'; public char left = 'a'; public char right = 'd'; //Add more public abstract void moveForward(); public abstract void moveBackward(); //Add functions for each input public void Update() { if(Input.inputString!="") { //only works for first input, //if you want keys within the frame update, //you need to iterate over it, char by char. char input =Input.inputString[0]; if(input == forward) moveForward(); else if(input == backward) moveBackward(); //Add checks for other inputs } } } 

Now you could write your keybindings to a simple text file. And just set those variables when you read them. ( havn't tried reading text/xml/json files in Unity but im sure it's possible )

The idea here is that the keys are stored in simple variables. Which you could easily change. It should be trivial then to read/write them away. So making an interface in game where you can set your keys shouldn't be a problem either.

Im not sure if this will work, I haven't actually tested it.

public abstract class InputController{ public char forward = 'w'; public char backward = 's'; public char left = 'a'; public char right = 'd'; //Add more public abstract void moveForward(); public abstract void moveBackward(); //Add functions for each input public void Update() { if(Input.inputString!="") { //only works for first input, //if you want keys within the frame update, //you need to iterate over it, char by char. char input =Input.inputString[0]; if(input == forward) moveForward(); else if(input == backward) moveBackward() //Add checks for other inputs } } } 

Now you could write your keybindings to a simple text file. And just set those variables when you read them. ( havn't tried reading text/xml/json files in Unity but im sure it's possible )

The idea here is that the keys are stored in simple variables. Which you could easily change. It should be trivial then to read/write them away. So making an interface in game where you can set your keys shouldn't be a problem either.

Im not sure if this will work, I haven't actually tested it.

public abstract class KeyInputController{ public char forward = 'w'; public char backward = 's'; public char left = 'a'; public char right = 'd'; //Add more public abstract void moveForward(); public abstract void moveBackward(); //Add functions for each input public void Update() { if(Input.inputString!="") { //only works for first input, //if you want keys within the frame update, //you need to iterate over it, char by char. char input =Input.inputString[0]; if(input == forward) moveForward(); else if(input == backward) moveBackward(); //Add checks for other inputs } } } 

Now you could write your keybindings to a simple text file. And just set those variables when you read them. ( havn't tried reading text/xml/json files in Unity but im sure it's possible )

The idea here is that the keys are stored in simple variables. Which you could easily change. It should be trivial then to read/write them away. So making an interface in game where you can set your keys shouldn't be a problem either.

added 157 characters in body
Source Link
Sidar
  • 3.6k
  • 2
  • 17
  • 28

Im not sure if this will work, I haven't actually tested it.

public abstract class InputController{ public char forward = 'w';  public char backward = 's';  public char left = 'a';  public char right = 'd'; //Add more public abstract void moveForward(); public abstract void moveBackward(); //Add functions for each input public void Update() { if(Input.inputString!="")   {   //only works for first input,  //if you want allkeys within the frame update,  //you need to iterate over it, char by char.   char input =Input.inputString[0];   if(forwardinput == forward)  moveForward(); else if(input == backward) //Call forward moveBackward()   //Add checks for other inputs and   interface it as a controller (polymorphous)}   } } 

Now you could write your keybindings to a simple text file. And just set those variables when you read them. ( havn't tried reading text/xml/json files in Unity but im sure it's possible )

The idea here is that the keys are stored in simple variables. Which you could easily change. It should be trivial then to read/write them away. So making an interface in game where you can set your keys shouldn't be a problem either.

Im not sure if this will work, I haven't actually tested it.

char forward = 'w'; char backward = 's'; char left = 'a'; char right = 'd'; if(Input.inputString!="") { //only works for first input, if you want all you need to iterate over it, char by char. char input =Input.inputString[0]; if(forward == input) //Call forward //Add checks for other inputs and interface it as a controller (polymorphous)   } 

Now you could write your keybindings to a simple text file. And just set those variables when you read them. ( havn't tried reading text/xml/json files in Unity but im sure it's possible )

The idea here is that the keys are stored in simple variables. Which you could easily change. It should be trivial then to read/write them away. So making an interface in game where you can set your keys shouldn't be a problem either.

Im not sure if this will work, I haven't actually tested it.

public abstract class InputController{ public char forward = 'w';  public char backward = 's';  public char left = 'a';  public char right = 'd'; //Add more public abstract void moveForward(); public abstract void moveBackward(); //Add functions for each input public void Update() { if(Input.inputString!="")   {   //only works for first input,  //if you want keys within the frame update,  //you need to iterate over it, char by char.   char input =Input.inputString[0];   if(input == forward)  moveForward(); else if(input == backward)  moveBackward()   //Add checks for other inputs   } } } 

Now you could write your keybindings to a simple text file. And just set those variables when you read them. ( havn't tried reading text/xml/json files in Unity but im sure it's possible )

The idea here is that the keys are stored in simple variables. Which you could easily change. It should be trivial then to read/write them away. So making an interface in game where you can set your keys shouldn't be a problem either.

Source Link
Sidar
  • 3.6k
  • 2
  • 17
  • 28

Im not sure if this will work, I haven't actually tested it.

char forward = 'w'; char backward = 's'; char left = 'a'; char right = 'd'; if(Input.inputString!="") { //only works for first input, if you want all you need to iterate over it, char by char. char input =Input.inputString[0]; if(forward == input) //Call forward //Add checks for other inputs and interface it as a controller (polymorphous) } 

Now you could write your keybindings to a simple text file. And just set those variables when you read them. ( havn't tried reading text/xml/json files in Unity but im sure it's possible )

The idea here is that the keys are stored in simple variables. Which you could easily change. It should be trivial then to read/write them away. So making an interface in game where you can set your keys shouldn't be a problem either.