- Home /
Answer by Mike 3 · Jul 01, 2010 at 06:16 PM
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
aham, i have been decoded your solution:), but if i undestood good enough, this script allows the OpenUrl() on the whole Label rect, does'nt it?
Yep it does, if it needs to be a smaller area, you can change the rect you use in the top part of the code
aham, then this rect is a static invisible layer-like area and it has an event listener... ?
if you want to think of it like that sure, it's more like basic maths though (checks if the mouse is inside the rectangle you supply), and the mouse button was released that gui frame
Answer by jashan · Jul 01, 2010 at 05:58 PM
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
Answer by winxalex · Apr 07, 2019 at 09:55 AM
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);
}
Answer by Raattis · May 17, 2014 at 10:37 AM
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.
You can use EditorStyles.linkLabel to get the blue text automatically
Your answer
![](https://koobas.hobune.stream/wayback/20220613063629im_/https://answers.unity.com/themes/thub/images/avi.jpg)