I have a unity scene which has 4 TMP_FieldInput's on it. (I am also using the new Unity Input system if it matters). What I'm trying to accomplish is to allow tabbing between the fields. The solution I have so far "sort of" works, but not correctly. When I press tab, I see the carat move to the proper InputField and start flashing as if it's ready for input. But when I start typing, nothing happens. The only way I can enter text into any of the 4 InputField's is to click on them first.
I've been looking for solutions, and have come across all kinds of suggestions, but nothing seems to work. No matter what, the carat moves, but I can't type until I click first.
FYI: Unity v. 2022.3.4f1 TMP: v. 3.0.6
Here is my current code:
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
public class InputFieldManager : MonoBehaviour
{
public TMP_InputField inputField1;
public TMP_InputField inputField2;
public TMP_InputField inputField3;
public TMP_InputField inputField4;
public int inputSelected = 1;
private void Awake()
{
inputField1.Select();
}
private void Update()
{
if (Keyboard.current.tabKey.wasPressedThisFrame && Keyboard.current.leftShiftKey.wasPressedThisFrame)
{
inputSelected--;
if (inputSelected < 1) inputSelected = 4;
SelectInputField();
}
else if (Keyboard.current.tabKey.wasPressedThisFrame)
{
Debug.Log("TAB!");
inputSelected++;
if (inputSelected > 4) inputSelected = 1;
SelectInputField();
}
}
private void SelectInputField()
{
switch (inputSelected)
{
case 1:
inputField1.Select();
break;
case 2:
inputField2.Select();
break;
case 3:
inputField3.Select();
break;
case 4:
inputField4.Select();
break;
}
}
}