Get number input from user

Hello,

Super easy question. I am trying to make it so when the user presses a number between 0-9 it will multiply that number by 3. I don’t know how to read in the numbers 0-9. The rest I can figure out.

Thanks in advance for anyones help!

private KeyCode keyCodes = new KeyCode { KeyCode.Alpha0, KeyCode.Alpha1, KeyCode.Alpha2, KeyCode.Alpha3, KeyCode.Alpha4, KeyCode.Alpha5, KeyCode.Alpha6, KeyCode.Alpha7, KeyCode.Alpha8, KeyCode.Alpha9 };

private void Update()
{
    for( int i = 0 ; i < keyCodes.Length ; ++i )
    {
         if( Input.GetKeyDown( keyCodes *)*

{
Debug.Log( i * 3 );
}
}
}
----
Otherwise, you can try the following, but I didn’t tested it
private void Update()
{
int start
for( int i = (int) KeyCode.Alpha0 ; i < (int) KeyCode.Alpha9 ; ++i )
{
if( Input.GetKeyDown( (KeyCode) i )
{
Debug.Log( i - ((int) KeyCode.Alpha0 ) );
}
}
}

Use this code as a basis for your script:

if (Input.GetKeyDown(KeyCode.Alpha1)) {
        // Do Stuff
}

The if statement will run on the first frame the key is pressed. The function inside the if statement takes in a property KeyCode.Value. Have a look here for the other values:

You can also use Input.anyKey

try this :

Debug.Log(Input.inputString);