Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

TextMesh Pro How to set rich text through script?

Discussion in 'UGUI & TextMesh Pro' started by better_walk_away, Jun 19, 2019.

  1. better_walk_away

    better_walk_away

    Joined:
    Jul 12, 2016
    Posts:
    291
    Hello everyone,
    I am trying to set the rich text of my TextMeshProUGUI component through script, but I can't.
    I ran the following code,
    Code (CSharp):
    1. myText.text = "< color =#E0E300>This is golden!</color>";
    but the text that showed up was just "< color =#E0E300>This is golden!</color>", it didn't parse the rich text tag, I wanted the text "This is golden!" to be yellow.

    How can we set the rich text through script?
     
    Last edited: Jun 19, 2019
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    You have extra spaces in the rich text tag.

    Code (csharp):
    1.  
    2. myText.text = "<color=#E0E300>This is golden!</color>";
    3.  
    Whenever you see the tag instead of its effect, this means the tag is invalid / incorrectly formatted.
     
  3. better_walk_away

    better_walk_away

    Joined:
    Jul 12, 2016
    Posts:
    291
    Yes, that's the issue! Many thanks.