Set Text Field To The Key of A Certain Input

For NPCs in my project when you walk up to them and look at them it says “Speak With Whoever” but I want it to show the interaction key.

I have an Input for Interact set to E and I want the text to say

" ‘E’ Speak With Whoever "

interactionText.text = (Input.GetKey("Interact").ToString() + " Speak With " + hit.collider.tag.ToString());

Call me crazy but couldn’t you just do

interactionText.text = "'E'" + " Speak With " + hit.collider.tag.ToString();

Well if the player were to change their controls I want it to pull from the input manager so that it changes.

I don’t think it’s possible sadly: Getting Input Manager button names in-game

Not sure if the other input system is any different: InputSystem/Packages/com.unity.inputsystem/Documentation~/Installation.md at develop · Unity-Technologies/InputSystem · GitHub

What? That’s a feature in pretty much every single game. The UI will update it’s prompts based on your actual keybindings. Why would Unity Technologies not think of this?

Am I really going to have to write my own input manager?

The InputAction object from the new input system package has a name property.

1 Like