Display the set up key for a button

I have a feeling this is going to be obvious and asked before, but I couldn’t find a response.

I would like to display a message, like:

Press SPACE to start.

But I want SPACE to be a variable, taken out from the user defined current controls.
I got so far:

string.Format("Press {0} to START", ???);

But Input.GetButton(“start”) has no subinformation what key the user set AFAIK. :frowning:

Hello,

You could try to use the KeyCode enumeration to store your variable. And then just call the .ToString() should display what you want.

In your case, it would be :

KeyCode key = KeyCode.Space;

string.Format(“Press {0} to START”,
key);

Check this post for more information

Just to make sure I know what you’re asking: You want to know what key is bound to a particular Input Axis. As far as I know there’s no way to do this with native Unity code at the moment. The way I see it you have two options:

You could build a custom Input Handler that lets players customize controls and which is used to check Unity’s native Input class (This is actually a good idea anyway. If you store this data in a ScriptableObject, you can test out different control schemes easily). This way you have a stored KeyCode that you can tie to a particular action (as opposed to the builtin method of just asking for the value of an axis), and you can just print that as the value.

But that’s pretty complicated and might be more than you’re looking to do. The alternative is to simply print the name of the axis you want the player to press, and they’ll know what key that axis stands in for.