Can I place a link (such as <a href>) into the GUI.Label?

Hi!

My client needs a link into the label text, what pointing to an outer URL. Can I script any html text into the Label or any GUI element?

Thx tzs007

You can't do that but what you can do is create a GUI.Button which opens a URL when it is clicked. Which is essentially the same as a link (only that you need a tiny little bit more coding ;-) ). Or, of course, depending on your layout needs a bit more coding.

What you need for this is: Application.OpenUrl And: GUI.Button or GUILayout.Button

In Addition to what Jashan said (Which deserves the solved mark), you could use this in your GUI:

if (Event.current.type == EventType.MouseUp && yourLabelRect.Contains(Event.current.mousePosition))
    Application.OpenUrl(yourUrl);
GUI.Label(yourLabelRect, yourUrl);

You could use a font, coloured blue with an underline if you want it to look like a hyperlink

It's a little bit more coding, but it's a label ;D

You can swap a button’s GUIStyle to label if you want. This way you can use GUILayout.

if (GUILayout.Button(yourUrl, GUI.skin.label))
{
    Application.OpenURL(yourUrl);
}

The result is essentially the same as Mike’s, but with less boiler plate code.

The downside with this solution is that you can’t easily place the clickable area inside a text block.

From Unity ReadMe code, you can full look and feel of link

 GUIStyle LinkStyle {
                get {
                    return m_LinkStyle;
                }
            }
    
            [SerializeField] GUIStyle m_LinkStyle;
    
    var  m_LinkStyle= new GUIStyle(EditorStyles.label);
                    m_LinkStyle.wordWrap = false;
                    // Match selection color which works nicely for both light and dark skins
                    m_LinkStyle.normal.textColor = new Color(0x00 / 255f, 0x78 / 255f, 0xDA / 255f, 1f);
                    m_LinkStyle.stretchWidth = false;
    
         bool LinkLabel(GUIContent label, params GUILayoutOption[] options) {
                    var position = GUILayoutUtility.GetRect(label, LinkStyle, options);
        
                    Handles.BeginGUI();
                    Handles.color = LinkStyle.normal.textColor;
                    Handles.DrawLine(new Vector3(position.xMin, position.yMax), new Vector3(position.xMax, position.yMax));
                    Handles.color = Color.white;
                    Handles.EndGUI();
        
                    EditorGUIUtility.AddCursorRect(position, MouseCursor.Link);
        
                    return GUI.Button(position, label, LinkStyle);
                }

if (EditorGUILayout.LinkButton(label))
Application.OpenURL(url);

If you can’t use EditorGUILayout.LinkButton, just do:

if (GUILayout.Button(label, EditorStyles.linkLabel))
  Application.OpenURL(url);