0

I have two TMP_InputField in unity. I am trying to automatically focus on and activate the other once the first one has an input. I have tried the following but for some reasons, it's not working for me.

using UnityEngine;
using UnityEngine.UI;
using TMPro;
using UnityEngine.EventSystems;

public class FocusBox : MonoBehaviour
{
    public TMP_InputField b1;
    public TMP_InputField b2;
 
    // Update is called once per frame
    private void Update()
    {
        if (b1.isFocused)
        {
            if (b1.text.Length > 0)
            {
                b2.Select();
                b1.DeactivateInputField();
            }

        }
        Debug.Log("is b1 focused after : " + b1.isFocused);

    }

}
Craving_gold
  • 189
  • 1
  • 14

1 Answers1

1

Not particularly sure what exactly you mean with "has an input".

However, I think you could use the OnValueChanged event on your TMP_InputField. Either assign a Callback via the Inspector or overwrite it programatically. Everytime your input changes, your Callback will be triggered.

anjelomerte
  • 286
  • 1
  • 9