How to use code to modify the Text property of TextMeshPro—Text
When using TextMeshPro today, I need to dynamically modify the text value of TextMeshPro. Of course, I quoted the namespace of the same name as TextMeshPro, but it did not achieve the effect I wanted.
using TextMeshPro;
private TextMeshPro mP_Text;
void Start()
{
mP_Text=GetComponent<TextMeshPro>();
mP_Text.text = "hello,world";
}
After consulting the documentation of TextMeshPro, I found that if you want to dynamically modify the value of TextMeshPro, you need to reference the TMPro namespace.
using TMpro;
private TMP_Text mP_Text;
void Start()
{
mP_Text=GetComponent<TMP_Text>();
mP_Text.text = "hello,world";
}
In addition, TextMeshPro’s method of implementing gradient fonts is also recorded simultaneously.
- Check the ColorGradient option of the TextMeshPro component.
- Select the rendering mode of Color Mode
- Select the color to be gradient
Single: single color
HorizontalGradient: horizontal gradient
VerticalGradient: vertical gradient< /span>
FourCornersGradient: Four corners change color