Search code examples
c#androidunity-game-enginetext-formatting

I would like to format the inputfield in a Unity3D Android App


I´m facing some troubles, I made an easy App where the user needs to input a time into an input field. The time have to be in a HH:mm format, I already figured out how to limit the characters, but I´m now wondering if it´s possible that the inputfield sets the colon itself. So that the user types in the hours then the colon appears and then he types the minutes. Is this possible? And how can I set it up like this.

Thanks in advance and friendly regards


Solution

  • Thanks for the initial idea,

    Chandrani Chatterjee

    But as I didn't find the TextWatcher Utility in Unity3D i did it in an other maybe easier Way. My Code is posted below, maybe someone can use it in advance.

    public void OnValueChanged(string input) 
    {
    
        if (input.Length == 2)
        {
            InputField.text = input+":";
            InputField.caretPosition = 3;
        }
    
    }
    

    To start the "Listening" I use the following Method.

    void Awake()
    {
        InputField.onValueChanged.AddListener(OnValueChanged);
    }
    

    Thanks to everyone, once again you Guys did help me.

    Best regards Tobi