text input question..

Hi…

i was seeing the site this information:

How can i make to limit to 3 chars the string?.. so the player can write only 3 numbers, only numbers, no letters, no numbers bigger than 3 units…

Off the top of my head, I don’t know how you can limit the control the input behaviour. But if that’s not possible to do, you could validate the input after the user has provided it. If it’s not a three digit number, display an error and prompt for input again. Keep doing that until they input good data.

From the link you provided, one approach would be to perform your additional checks in the “normal text input” section. Instead of just adding the text to the end of the text object, check to see if it is a number first, really a digit. If it is a digit, add it to the “guiText.Text” object, increment a counter, and then loop again. If it is not a digit, ignore it. Once your counter reached “3”, or what ever you wanted, then exit the loop.

Actually, what you want is this: Unity - Scripting API: GUI.TextField

It has built-in methods for limiting the string gathered.

What you just saw was the string of all input added in a single frame, not the text entered over multiple frames.