2
\$\begingroup\$

How would I get the physical button name (A, B, C) by the name set up in the Input Manager (Fire1, Reload, Jump)? For instance, if the player needs to reload his gun, I want to print "PRESS [RELOAD BUTTON] TO RELOAD" on screen where [RELOAD BUTTON] is whatever he assigned it to. I don't see anything helpful in the Input class, where else can I look?

\$\endgroup\$

2 Answers 2

3
\$\begingroup\$

Sadly, the only way to do it the way you want to is to get or write your own custom input manager. That would also give you the opportunity to assign representative images to each input (ie picture of button for A-button) and get better control over thumbstick deadzones. Unity's input manager is really more suited to defining names for input axes on different devices, rather than translating those inputs into gameplay terms.

However, if the platform you're targeting has a fixed set of input buttons that shouldn't be too much of an issue. Although it's not the best practice, you can hard code the axes to the corresponding buttons.

\$\endgroup\$
1
\$\begingroup\$

Manipulating the Input Manager in Script gives a solution for editor script:

/// <summary>
     /// Gets all the input axis defined in the project's Input manager
     /// (gets it from ProjectSettings/InputManager.asset)
     /// </summary>
     public static List<string> GetInputAxis()
     {
         var allAxis = new List<string>();

         var serializedObject = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0]);
         var axesProperty = serializedObject.FindProperty("m_Axes");

         axesProperty.Next(true);
         axesProperty.Next(true);
         while (axesProperty.Next(false))
         {
             SerializedProperty axis = axesProperty.Copy();
             axis.Next(true);
             allAxis.Add(axis.stringValue);
         }

         return allAxis;
     }

Unfortunately, this is only safe in the editor, and not while the game is running.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .