I want to put commas automatically as the player enters in an integer number input field. For example; when the player enter 10000 in the input field, it will be shown as 10,000 or when they enter 1000000, it will be shown as 1,000,000. The player won’t put comma in the input field.
I would like the keep the input as a number without any comma if possible. For example; when the player enters 10000, it will be shown as 10,000, but when I read the input field, it will give me “10000”. Is that possible?
InputFields have an event for OnValueChanged. You simply need to hook into that event, grab the value from the inputfield as a person types, add commas as needed, and then display it to a text object. The value of the inputfield.text will remain numbers, but the visual part will have the commas that you put in.
“display it to a text object”.
I want to display it on the input field. As the player types a number, commas are added if needed like an input field in bank applications.
You need to understand, inputfields don’t display text. Text objects do. You simply place the text window over the input field and add the commas. Take a look at the current inputfield object to understand how it is setup. The part that might not work right is the cursor. So actually, I think you’ll just need to add the commas to the inputfield text and then just store the value without the commas if you want to preserve the original value. That way when Unity passes the text from the inputfield to the connected text object, the commas are in place and the cursor is where it needs to be.