I am using the „new“ Input System of Unity, which I really like.
For my Interaction Project I needed the mapping of an action in a human readable form.
First add
using UnityEngine.InputSystem;
Then, in your class where you need it, for example a config dialog, or in my case, to show the correct key for an action on an Actionable Object when the player looks on it.
public PlayerInput playerInput; public InputActionMap actionMap;
You can either drop the PlayerInput component in your Game Gameobject into it in the Inspector or just let it be initialized in the Start method.
Also in the Start() method :
if (playerInput == null)
playerInput = GetComponent<PlayerInput>();
actionMap = playerInput.currentActionMap;
ReadOnlyArray<InputBinding> actions = playerInput.actions["Interaction1"].bindings;
foreach(InputBinding binding in actions)
{
Debug.Log(binding .ToDisplayString());
}
Interaction1 is the action I am looking for. I then iterate through all the bindings and display them as a readable string. (In this case I only have one binding though)
The action is mapped to the keyboard key E, so I get a plain and nice E as result, which is exactly what I needed.
References :