On a typical text UI component I would just use “Text” and make it a public variable. I just need to know how to change the text using textmesh pro? Or am I better off just using a text UI component for this?
Thanks.
On a typical text UI component I would just use “Text” and make it a public variable. I just need to know how to change the text using textmesh pro? Or am I better off just using a text UI component for this?
Thanks.
There are two TMP components who both derive from TMP_Text. They are both in the TMPro namespace.
The first component of type is designed to replace the old TextMesh which uses the MeshRenderer.
The 2nd of type is designed to replace UI.Text and designed to work with the CanvasRenderer and Canvas system.
This information is also available in the FAQ - Question 9 on the TextMesh Pro user forum.
using UnityEngine;
/// Include the name space for TextMesh Pro
using TMPro;
public class Example : MonoBehaviour
{
private TMP_Text m_TextComponent;
private void Awake()
{
// Get a reference to the text component.
// Since we are using the base class type <TMP_Text> this component could be either a <TextMeshPro> or <TextMeshProUGUI> component.
m_TextComponent = GetComponent<TMP_Text>();
// Change the text on the text component.
m_TextComponent.text = "Some new line of text.";
}
}
Exactly the information I needed. Thanks!
The VS editor says using the TMPro directive is unnecessary, yet the TMP_Text type could not be found. I am using Unity 2018.4.3 so maybe this is done differently in this version of Unity?
Nothing has changed in terms of the requirement to use “using TMPro;”
This was very helpful and has allowed me to attached live text to all sorts of objects, updating during the game.
I did need the namespace “using TMPro” but I didn’t seem to need the step “private TMP_Text m_TextComponent;”
So having declared the TMP_Text variable with the line “public TMP_Text theTMPgameobject;” I was then able to populate the text with "theTMPgameobject.text = “the text I wanted here”;
Fantastic stuff… many thanks!!
Thank you very much.
Thanks!!!
link is broken
Thanks!!!
you’re a lifesaver my guy