0

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";
}
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
zackrn23
  • 3
  • 2

2 Answers2

0

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

Martin_0
  • 145
  • 2
  • 12
0

You can use the SetText(string text) method

GameObject.Find("periode12").GetComponent<TextMeshProUGUI>().SetText("Hello World");