How to draw a text underline?

Hi, everybody! I need your help.

In GUIText , Label, or other captions, some keywords need to be signed by underline.

like this

I can't fix it. Could you give me any good suggestion?

Unity imports a given font exactly as it is and can only use the original version (ie, it can't add styles on the fly). To get underlines, you should import an underlined version of the font separately and use it wherever necessary.

Thanks for repay

WOW, how stupid this is! I'm pulling my hair out trying to make a link look like a link. It's so dumb having to import every font a million times for every variation, and that Unity GUI is incapable of such basic tasks.

7 Likes

[quote=“pallzoltan”, post:4, topic: 405679]
WOW, how stupid this is! I’m pulling my hair out trying to make a link look like a link. It’s so dumb having to import every font a million times for every variation, and that Unity GUI is incapable of such basic tasks.
[/quote]
The answer above isn’t completely true, because underline could be done with custom GUIStyle for your label using the background graphics. You could also set different graphics for normal, hover etc.

Bold and italic couldn’t be done this way though.

Also, check out this link for CSS in Unity.

1 Like

I found a way that worked for me. Basically, I get the rectangle of the last GUILayout item and display a line of the same width.

I posted some code here: http://answers.unity3d.com/questions/133318/how-to-render-underlined-text-in-unity.html#answer-748430

Correct me if I'm wrong but ain't it possible nowadays with a RichText option ?

Where to find underlined arial font?

[quote=“Ghorre”, post:7, topic: 405679]
Correct me if I’m wrong but ain’t it possible nowadays with a RichText option ?
[/quote]

Rich text in Unity doesn’t seem to support Underline yet, although I didn’t try it: http://docs.unity3d.com/Manual/StyledText.html

1 Like

Not trying to necro this, just this is the one that google pulls up when one searches for how to underline text in the UI (even on 5.6.1), so...
The location of one's fonts in Windows is typically C:\Windows\Fonts. Unity will import and use most ttfs... (Adding for posterity, and new users.)

My solution to the lack of underline was to duplicate the text object and replace the text to fill in the underline with adjacent underscores. The underscores look solid as long as you keep the transform of both text objects the same.

4 Likes

[quote=“OLP”, post:9, topic: 405679]
Rich text in Unity doesn’t seem to support Underline yet, although I didn’t try it: http://docs.unity3d.com/Manual/StyledText.html
[/quote]

4 years later … this ought to be the answer, but still not fixed in Unity 2017. Might be fixed in 2018, but many people still using 2017 as the current most-stable release, so …

I don't get the problem.

With TextmeshPro and works fine for me.

6 Likes

You can just create a textureless image, shape it as a line and put it under your text

2022 and still a simple task as underline has such complex solutions

I made underline like this,
Make Image component, and Set its parent the text component.
and add component "Content Size Filter" to text.
then the size of RectTransform is changed according to length of text.
also its child(Image component) also change.

Hello, here is my tip:
create a 1px black bottom border on the Label element.

9457970--1328429--Sans titre.png