Unity implements dynamic modification of TextMeshPro fonts and color-changing fonts

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.

  1. Check the ColorGradient option of the TextMeshPro component.
  2. Select the rendering mode of Color Mode
  3. Select the color to be gradient
    Four rendering modes
    Single: single color
    HorizontalGradient: horizontal gradient
    VerticalGradient: vertical gradient< /span>
    FourCornersGradient: Four corners change color
    Illustration

Guess you like

Origin blog.csdn.net/a2765544988/article/details/134114521