- Home /
How to use xml in text component text field
I remember TANKS! the Unity tutorial use xml in text component text field to change text color.The code like this(it in TankManager.cs):
m_ColoredPlayerText =
$"<color=#{ColorUtility.ToHtmlStringRGB(m_PlayerColor)}>PLAYER {m_PlayerNumber} </color>";
I think this is very useful trick.But I cant find more info ,like how many tag I can use,how many attribute the have.Can I get some help in here.
PS:My English is not good, so if it have some info and real conspicuous. I maybe just not find it.
Example:
public Text _text;
void Start ()
{
_text.text = $"<color=#ff0000>$$anonymous$$</color> and <color=#00ff00>Jack</color>";
}
It can make different color word just use single line;
Answer by Xarbrough · Mar 06, 2018 at 03:10 AM
You want to use Rich Text markup. It doesn't have anything to do with xml, by the way. Rich Text (or "Styled Text") in Unity is their own version of a concept originally from HTML. It's not strictly compatible with other standards, which is why you should refer to the documentation.
Remember to set the richText property on the text component to true.
Thank you a lot,it is what I want. That why I cant find it Rich Text markup,not xml. Thanks!
Your answer
![](https://koobas.hobune.stream/wayback/20220612154019im_/https://answers.unity.com/themes/thub/images/avi.jpg)