MXPDMN
1
I created a tmp-inputfield in unity in code, but no cursor is displayed.
TMP_InputField tmpInputField = A.AddComponent<TMP_InputField>();
TextMeshProUGUI text = A.GetComponentInChildren<TextMeshProUGUI>();
tmpInputField.textComponent = text;
tmpInputField.textViewport = text.rectTransform;
You can’t create a TMP_InputField
from scratch like this; you should use:
TMP_DefaultControls.CreateInputField(Resources resources)
.
This is how it's done in the editor.
// TMPro.EditorUtilities.TMPro_CreateObjectMenu : 133
[MenuItem("GameObject/UI/Input Field - TextMeshPro", false, 2037)]
static void AddTextMeshProInputField(MenuCommand menuCommand)
{
GameObject go = TMP_DefaultControls.CreateInputField(GetStandardResources());
PlaceUIElementRoot(go, menuCommand);
}
You’ll just need to pass a Resources instance with Resources.inputField
set to whatever you want the background sprite of the field to look like.