I have TMPro Input field and want to input decimal numbers only. On PC I need to press comma to seperate, point does not work. My phone does not support commas only points so I can only put integers.
The only code I used for that is the following:
- I grabbed a reference with public TMP_InputField
- I read the text with inputField.text
But that is not the problem. I don’t change the text in the input field at any time. I just read it.
In the inspector I changed the content type from standard to decimal number.
I hae linked an image here, because I cannot post my own (I need more reputation).
I tried changing PC language before building, that did not work, I still needed to input commas. I tried replacing commas with points. That did not work either, Unity was removing the point before OnValueChanged event. Is there any way to change the seperation char or just set it to point by default?
5
Can’t you just check when the input field is edited if the typed text corresponds to decimal ?
public InputField inputField;
public List<string> supportedCharacters = new List<string>(){"1","2","3",".",","};//Fill here your characters
public void Start() //Call a function whenever the input field is edited
{
mainInputField.onValueChanged.AddListener(delegate {ValueChangeCheck(); });
}
//
public void ValueChangeCheck() //Called when the value changed
{
foreach(string character in mainInputField.text){
if(!supportedCharacters.Contains(character))
{//Do sthg to delete the uncorrect character}
}
}
This would give you more control on what you can and can’t type.
3