- Home /
Checking if Input.inputString is a number
Hello, I would like an if statement that checks if a number has been input.
if(Input.inputString!=null)
{
input += Input.inputString;
}
Instead of checking if its null is there a (quick) way of checking if the input has been a number from either above the qwerty or the alpha key pad?
Thanks
Answer by theundergod · Feb 23, 2013 at 11:29 PM
You can use
int.TryParse();
or
float.TryParse();
Let me know if you need clarification on how to use it.
Yeah really sure here, something like this? if(Input.inputString==int.TryParse())
TryParse returns a bool if successful so:
string numString = "1234";
int number;
if(int.TryParse(numString, out number))
{
Debug.Log ("String is the number: " + number);
}
Hope that helps! :)
Your answer

Follow this Question
Related Questions
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
How to make floating mobile keyboard in mobile game ? 0 Answers
Transition based off day length speed? ( day/night system) 1 Answer
Input keycode string not working 2 Answers
New Input axis with Numpad Keys 2 Answers