OK I got a new joystick and have been stumped on how to get the input mappings to work.
Well I was going through the process of trying each axis in game, until I figured out a simpler way to do it, map all the 10 input axis for each joystick and write a simple program to display them.
With the following code and some mind numbingly boring Ctrl+D edit and repeat work in the input manager I have found all the relevant buttons and axis for my joystick
PS Unity please improve the InputManager to allow dynamic generation of “Axes” or if there is a way to do it via code please let me know.
Anyway here is the amazing code that helped me out:
// Arowx.com 2013 - free to use and improve!
using UnityEngine;
using System.Collections;
public class JoystickTester : MonoBehaviour {
public TextMesh joysticks;
public TextMesh[] inputText;
public TextMesh[] buttonText;
public int numSticks;
void Start()
{
int i = 0;
string sticks = "Joysticks\n";
foreach (string joyName in Input.GetJoystickNames())
{
sticks += i.ToString() + ":" + joyName + "\n";
i++;
}
joysticks.text = sticks;
numSticks = i;
}
/*
* Read all axis of joystick inputs and display them for configuration purposes
* Requires the following input managers
* Joy[N] Axis 1-9
* Joy[N] Button 0-20
*/
void Update () {
for (int i = 1; i <= numSticks; i++)
{
string inputs = "Joystick " + i + "\n";
string stick = "Joy " + i + " Axis ";
for (int a = 1; a <= 10; a++)
{
inputs += "Axis "+ a +":" + Input.GetAxis(stick + a).ToString("0.00") + "\n";
}
inputText[i - 1].text = inputs;
}
string buttons = "Buttons 3\n";
for (int b = 0; b <= 10; b++)
{
buttons += "Btn " + b + ":" + Input.GetButton("Joy 3 Button " + b) + "\n";
}
buttonText[2].text = buttons;
}
}
So you need to create a new scene, add in a 3D TextMesh object link it to the joysticks field and run it to find out how may devices you have and what they are called.
Add in the appropriate number of TextMesh objects for each device you want to test.
The slow and arduous bit is adding input axes to the InputManager:
For joystick axes, create a Joystick Axis, with the appropriate axis and joy num, naming it Joy A Axis B, where A is the joystick number and B the axis number (note X axis = 1, Y = 2 then 3 to 10).
For buttons just ensure the name follows the Joy A Button B pattern and the joy num match and set the type to key or mouse button and the positive button name = joystick button B.
If anyone has a faster way to do this please let me know.:(
Now run your joystick/input tester and work out which axis map to which inputs.
Tada you will have the input axis and buttons mappings you need to use your controller.