unity-game-engineinput

Unity TMPro InputField Decimal seperator


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:

  1. I grabbed a reference with public TMP_InputField
  2. 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?


Solution

  • Ok, after a lot of research I found out about Unity's Culture Info Class. I called

    CultureInfo.CurrentCulture = new CultureInfo("en-US");
    CultureInfo.CurrentUICulture = new CultureInfo("en-US");
    

    To set default culture and UI culture to a culture that uses decimal point and not comma.