hello i would like to only detect key input if it a number is pressed, I am using the following code.
Regex rgx = new Regex("[^0-9]");
if (e.isKey)
Debug.Log("Detected character: " + e.character);
I cannot combine these two bits to get it to only detect the number input from the keyboard.
Any help is appreciated
p.s. i am using c#
Check Event.keycode and whether it’s Keypad0, Keypad1, etc.
Why would you use Regular Expressions to detect if a numeric key was pressed? Sounds like you got the wrong tool for the job. You could use char.IsDigit to find out if it is a digit.
void OnGUI () {
Event e = Event.current;
bool isKeyDown = e.type == EventType.KeyDown;
bool isDigit = char.IsDigit(e.character);
if (isKeyDown && isDigit)
Debug.Log("Digit character pressed: " + e.character);
}