How to WRITE TEXT MESH PRO from script in Unity

Опубликовано: 16 Октябрь 2024
на канале: GDT Solutions
25,057
304

In this video we see how to use Text Mesh Pro to write text in Unity, which is a way to print text to screen. We also see how to change that text from script.

For this exercise we create two type of TextMesh Pro texts, one text for the User Interface, this text must be attached to a Canvas GameObject and another Text Mesh Pro Text for the World Space, the difference between both is that the first one uses a Canvas Renderer component so it has to be inside a Canvas so it can be rendered, while the other Text Mesh Pro uses a Mesh Renderer component like the 3D models, so it can be placed anywhere in the world.

To write text mesh pro from script in Unity we need to define a TMP_Text variable inside our script, assign the text mesh pro object in the inspector, the use that variable to write text mesh pro inside the script. Let's suppose you define a variable called "myText", then to write that text mesh pro variable in the script you use the following instruction:

myText.text = "Text you want to write from script";

Text Mesh Pro has become the standard solution for displaying text on screen, while the old Text component has moved to the "Legacy" section.

____________________________________________________________
LinkedIn:   / gamedevtraum  

Downloads: https://gamedevtraum.itch.io/
____________________________________________________________

TIMESTAMP
0:00 Creating Text Mesh Pro objects.
1:21 Creating the control script to change text by code.
1:42 Working on the Script.
1:59 Declaring the variables.
2:54 Variables initialization.
3:47 How to change Text Mesh Pro text by script in Unity.
4:34 Test and ending