Press J to jump to the feed. Press question mark to learn the rest of the keyboard shortcuts
Community Details

108k

Subscribers

433

Online

News, Help, Resources, and Conversation. A User Showcase of the Unity Game Engine.

Create Post
2
Posted by
Hobbyist
1 year ago
Archived

Help with TextMeshPro

How can I change the text from within a script? (I'm having the component on an empty game object, and not on a canvas)

6 comments
100% Upvoted
This thread is archived
New comments cannot be posted and votes cannot be cast
level 1

You need using TMPro; at the beginning.

To change the text, use GetComponent<TextMeshProUGUI>() to get the component and then the SetText() method.

level 2
Hobbyist
Original Poster1 point · 1 year ago

thanks

level 2
[deleted]
1 point · 1 year ago

Do you know if you can change the text from an animation, I've had some issues with that, wherever I change it on the animation time line it applies it to the entire timeline.

level 3

Not sure if I'm understanding what you're saying. You can call methods from the timeline of an animation and change the text via script.

level 4
[deleted]
1 point · 1 year ago

Thats how I thought it should work too, and does for almost all the fields I've tried. For example, I'm changing the gradient, the size, the transparency, the position, etc... but if I try to change the text its like it takes effect outside of the timeline and just changes the text globally as if it had no idea I was editing the timeline.

level 1

[your gameobject].GetComponent <TextMeshProUGUI> ().text = [new text];

Cookies help us deliver our Services. By using our Services or clicking I agree, you agree to our use of cookies. Learn More.