Just to make sure before I embark on making my own, Unity’s input manager is not accessible from a script (to change control keys in-game), correct?
Thanks!
Just to make sure before I embark on making my own, Unity’s input manager is not accessible from a script (to change control keys in-game), correct?
Thanks!
That’s true, but you can’t (yet?) change control keys from script either. So to write your own, you’d have to reimplement the entire input class…
Off the top of my head, it seems like it’s only the Axis input that is hard to change. Any GetButton can be remapped in scripts with something like
private var buttonNames : String[];
function SetButton (i : int, s: String) {
buttonNames[i] = s;
}
//or
function SetButtonByInput (i : int) {
while(!Input.anyKey) yield;
buttonNames[i] = Input.inputString;// you would need to detect if multiple keys were hit in one frame...
}
function Update () {
if(Input.GetKey(buttonNames[0])
transform.Translate(transform.forward);
}
Mimicking the GetAxis functions for non-analogue sources shouldn’t be too hard either. For the analogue axis, you would probably have to set up an axis for every source in the InputManager and then use a similar method as above to set it to the desired control.
careyagimon, that was the plan. Then use some GUI and PlayerPrefs to allow the user to remap the axes, so really it will just be a lookup table. I need this more for Windows since there is no built in way to change the input settings and I’ve got a joystick that maps the buttons and axes differently on Windows and Mac.
If the button mappings are static between Windows and Mac, ie if you’re supporting one controller (like an Xbox 360 controller), you can do:
static function GetButton(button:String)
{
if(Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsWebPlayer)
return Input.GetButton(button + "_win");
else
return Input.GetButton(button);
}
I did this for a game jam that used Guitar Hero controllers, and worked well enough. I had pass-through functions for all of the functionality. Certainly not ideal, though…
I thought about that (it is the Xbox controller I’m referring to) but want to make it more generic in case other joysticks are used with my app.