Search code examples
c#unity-game-enginetextmeshpro

Input from a dynamic input box


I am trying to add text to a dynamic input box in Unity. I am using the Text Mesh Pro Asset. The inputbox is created where I want it to be, but the text does not display.

The code is as follows:

enter image description here

public GameObject inputs;
public GameObject beginplek;

// Start is called before the first frame update
public void Start()
{
    GameObject newinput = Instantiate(inputs, beginplek.transform.localPosition, beginplek.transform.localRotation) as GameObject;
    newinput.transform.SetParent(GameObject.FindGameObjectWithTag("aaaa").transform, false);
    newinput.name = "periode12";
    GameObject.Find("periode12").GetComponent<TextMeshProUGUI>().text = "Hello World";
}

Solution

  • If you use a TextMeshPro Input Field the component you want to access should be TMP_InputField instead of TextMeshProUGUI