Answer the question
In order to leave comments, you need to log in
How to get int from inputField?
how to get int from inputField ?
Answer the question
In order to leave comments, you need to log in
Forbid to enter everything except numbers? As a result, there will be a number
If you enter a crap there, then no way. And if the correct number, then as you have in the previous question.
InputField input = ...;
int number = int.Parse(input.text); // если в input.text будет лежать не число, то будет FormatException
InputField input = ...;
if(int.TryParse(input.text, out var number) {
// используем number. В этом случае FormatException не выпадет, но тогда будет возникать ощущение, будто ничего не работает.
}
In the inspector, you set the Input Field element itself to Integer (then you can enter only integers in the field), the output will still be a string and then you will convert it to int.
InputField numberInputField = ...; //тут подключаешь своё поле с которого читаешь
int number = int.Parse(numberInputField.text); //записываешь значение в переменную
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question