Input.GetKeyDown(KeyCode.Alpha) as an integer?


Is there an built-in option to take Input Alpha buttons that represents number keys as an integer?

So, for example, instead of doing this:

if (Input.GetKeyDown(KeyCode.Alpha1))
else if (Input.GetKeyDown(KeyCode.Alpha2))

Where “ExecuteFunction” is any function that takes integer.

Do something like this:

ExecuteFunction(/*Input as an integer*/);

Or the only way to achieve this is to create custom class for that particular case?

If there is any source that you can link in - that’s great, since I couldn’t find.

Thank you in advance.

you could write this a bit more simple like this:

        for(int i=0;i<10;i++)

this is possible since a KeyCode is just an enum and can thus be simply casted into an integer (or as in the code the other way around)
As you can see when hovering over the KeyCode.Alpha0 it has the value 48. All following numbers are just assigned to the following numbers upwards.