- Home /
Richtext doesn't work
For some reason, RichText in GUI doesn't work for me. Nothing -colors, other things, even as basic thing as bold face doesn't work. I have following code:
Rect descriptionRect = new Rect(invrect.x+((invrect.width/4)*4),invrect.y,invrect.width/3,invrect.height);
GUIStyle boxstyle = GUI.skin.box;
boxstyle.wordWrap=true;
boxstyle.alignment = TextAnchor.MiddleLeft;
boxstyle.richText=true;
GUI.Box(descriptionRect,"<color:a40000>Name:</color> "+Globals.playerInventory.getItemName(Globals.SelectedItemID)+"\n"+"<color:c69500>Amount:</color> "+Globals.playerInventory.getItemAmount(Globals.SelectedItemID).ToString()+"\n"+"<color:00a400>Description:</color> "+Globals.playerInventory.getItemDescription(Globals.SelectedItemID),boxstyle);
Should work, right? Nope - even since I specifically set richText to true, text still turns out as:
<color:a40000>Name:</color> placeholder name <color:c69500>Amount:</color> 1223 <color:00a400>Description:</color> placeholder description
Not even tags are removed which would mean that something is going on behind the scenes. This is same even for most basic tags such as <b> or <i>.
Answer by TrickyHandz · Oct 06, 2013 at 06:59 PM
EDIT: Intially, I thought this was because of a null font setting, but I have since tested with and without a font being assigned. If the font is not assigned, it does use the default Arial font despite returning a null value for the font.
The real problem exists in the syntax of your color tags which I overlooked earlier. Your tags should be declared like this in your string:
string colorName = "<color=#a40000>Name:</color>";
Apparently the use of a colon is disallowed for tagging in this case. Additionally, I dug up this nice reference on RichText from the manual that has predefined color tags you can use like this:
string testColor ="<color=red>Name:</color>";
Yeah, but for this particular script Inspector is already cluttered and I don't want to clutter it anymore.
Also I'm doing
GUIStyle boxstyle = GUI.skin.box
Isn't that enough?
//edit: tried adding your code and it doesn't do the trick.
I have been able to pull this off without declaring a font and edited the answer above to reflect my new findings.
Thanks! Now it works. I guess serves me right for playing Blockland - in modding for this game, tag for color was with colon ins$$anonymous$$d of equal sign.
@darkhog, you have made me dig up stuff about the GUI system I haven't used in a long time. It's rather fun for me. Since it works, mark the answer as accepted when you have a chance. Happy Coding!
Your answer
![](https://koobas.hobune.stream/wayback/20220613115429im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
4.6 GUI Button inside a scrolling Text Box 0 Answers
c# - void method from external class. 2 Answers
drawing a box with GUI 3 Answers
Why is my GUI pushed over to the right? 0 Answers