Press J to jump to the feed. Press question mark to learn the rest of the keyboard shortcuts
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];

Community Details

116k

Subscribers

918

Online

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

Create Post
Rules and Wiki

Please refer to our Wiki before posting! And be sure to flair your post appropriately.

Related Communities
r/Unity2D

45.5k subscribers

r/UnityAssets

3.8k subscribers

r/unity_tutorials

13.9k subscribers

r/gamedev

320k subscribers

r/gamedesign

63.8k subscribers

r/justgamedevthings

9.0k subscribers

r/indiegames

29.6k subscribers

r/playmygame

17.1k subscribers

r/blender

111k subscribers

r/learnprogramming

917k subscribers

Tutorials

Brackeys

  • Beginner to Intermediate
  • 5 to 15 minutes
  • Concise tutorials. Videos are mostly self contained.

Sebastian Lague

  • Beginner to Advanced
  • 10 to 20 minutes
  • Medium length tutorials. Videos are usually a part of a series.

Catlike Coding

  • Intermediate to Advanced
  • Text-based. Lots of graphics/shader programming tutorials in addition to "normal" C# tutorials. Normally part of a series.

Makin' Stuff Look Good

  • Intermediate to Advanced
  • 10 minutes
  • Almost entirely shader tutorials. Favors theory over implementation but leaves source in video description. Videos are always self contained.

Quill18Creates

  • Beginner to Advanced
  • 30 minutes to 2 hours.
  • Minimal editing. Mostly C#. Covers wide range of topics. Long series.
Cookies help us deliver our Services. By using our Services or clicking I agree, you agree to our use of cookies. Learn More.