How can I instantiate gameObject as UI.Text in unity

Hello, I’m working on my game. I’m trying to instantiate text and then change instantiated text’s text value. Like this:

But I’m getting an error like this, and I cannot find the way to solve it.


numbersfortune and objectsfortune are structs. Can you help please? Thanks. Aghayev Teymur.

That might only work if the SimpleText is in a field like public Text SimpleText;. It can automatically instantiate the GameObject then get the component for you. It can’t if it looks like public GameObject SimpleText;.

You can change the field to text, or instantiate as GameObject, then do GetComponent().