Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Moving between Inputfields with Arrow Keys or max characters

Discussion in 'UGUI & TextMesh Pro' started by Czar-Man, Dec 11, 2016.

  1. Czar-Man

    Czar-Man

    Joined:
    May 10, 2013
    Posts:
    20
    I'm working on trying to move my typing cursor between different input fields. I have a rough idea about how it would work in C#:

    • GameObject to hold Inputfields
      • InputField1
      • InputField2
      • InputfField3
    In the GameObject, I would include code that does the following:
    Start()
    {
    Create array with all InputFields.
    Start typing cursor in first InputField.
    Disable exiting InputField with mouse
    }

    Update()
    {
    If Right Arrow or Space Key is pressed:
    If minimum number of characters are typed in CurrentInputField
    If the CurrentInputField is not the last
    Move CurrentInputField to the Next Input Field
    If Left Arrow or Backspace is pressed:
    If CurrentInputField has characters in them:
    Delete character behind
    Else If CurrentInputField is not the first:
    Move CurrentInputField to the PreviousInputField
    If Enter is pressed:
    If there are characters in the InputField:
    Submit
    }

    Any help and ideas to improve this are greatly appreciated.
     
    Last edited: Dec 11, 2016