How does the AventureGame script update the TextMeshPro object?

I must have missed something, or not be understanding…After we add the TextMeshPro objects to our scene, how do we set one of them up as the Text Component for the Game object?

For me, it’s not letting me set the Text Component to either of the TMP objects I created. Ideas?

Hi,

There should be a variable of type TextMeshProUGUI in your script. If that’s the case, you very likely assigned a reference to the TMP object in your Hierarchy to that variable. And when your code appears to update the text property of the variable, it actually updates the text property of the TMP object.

Text components can be assigned to variables of type Text only, not to variables of other types.

Did this clear it up for you? :slight_smile:

1 Like

Hi Nina,

This did clear things up for me!

Previously, I had this line of code in AdventureGame:

[SerializeField] Text textComponent;

After reading your comment, I figured out that I needed this line of code instead:

[SerializeField] TMP_Text textComponent;

Good job on fixing the issue. :slight_smile:


See also:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms