Hi. I have an issue with the use of a joystick with the new Unity UI. I will take the horizontal axis as an example :
The left stick axis is binded under :
“L_XAxis_1” : Used for the gameplay itself. Only one entry in the input manager use this name.
“Menu_Horizontal” : Used for the menus. Severall entry use this name (for the keyboard and the D-Pad).
“L_XAxis_1” works fine, but “Menu_Horizontal” is keeping its default value of 0 when I move the axis.
Is there a reason for this ? Can’t we bind an axis under different names ? Or am I missing something ?
Thanks for your help.
ps : I am using Unity 5.2.1f1
Ok, so I have my answer. You can’t have the same input binded under several names. To overcome this problem, I made a small script that set the axis in the StandaloneInputModule by checking the input being used.
public string _HorizontalInputs;
public string _VerticalInputs;
private string[] _Hor;
private string[] _Ver;
void Update()
{
for( int i = 0; i < _Hor.Length; i++ )
{
if( Input.GetAxisRaw( _Hor[i] ) != 0.0f )
{
StandaloneInputModule test = EventSystem.current.currentInputModule as StandaloneInputModule;
test.horizontalAxis = _Hor[i];
break;
}
}
for( int i = 0; i < _Ver.Length; i++ )
{
if( Input.GetAxisRaw( _Ver[i] ) != 0.0f )
{
StandaloneInputModule test = EventSystem.current.currentInputModule as StandaloneInputModule;
test.verticalAxis = _Ver[i];
break;
}
}
}
void Start()
{
_Hor = _HorizontalInputs.Split (new string[] {", "}, System.StringSplitOptions.RemoveEmptyEntries);
_Ver = _VerticalInputs.Split (new string[] {", "}, System.StringSplitOptions.RemoveEmptyEntries);
}
You could have the array directly as public, but considering there is only three small strings, I choose to split one. Well, that’s just depend on how you prefer it…