Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by tzs007 · Jul 01, 2010 at 05:22 PM · guilabelurllink

Can I place a link (such as ) 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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

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

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tzs007 · Jul 06, 2010 at 09:41 AM 0
Share

thank you for your solution!

avatar image tzs007 · Jul 06, 2010 at 10:35 AM 0
Share

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?

avatar image Mike 3 · Jul 06, 2010 at 10:46 AM 0
Share

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

avatar image tzs007 · Jul 06, 2010 at 09:37 PM 0
Share

aham, then this rect is a static invisible layer-like area and it has an event listener... ?

avatar image Mike 3 · Jul 06, 2010 at 10:38 PM 0
Share

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

avatar image
8

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tzs007 · Jul 06, 2010 at 09:41 AM 0
Share

thank you for your solution!

avatar image
1

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);
                 }






Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hawaiian_lasagne · Nov 24, 2020 at 11:45 PM 0
Share

You can use EditorStyles.linkLabel to get the blue text automatically

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Possible to change GUI.Label fontsize without using GUIStyle? 1 Answer

GUI LABEL behind viewport rect of mini map? 1 Answer

4.6 GUI Button inside a scrolling Text Box 0 Answers

Timer Between Labels 2 Answers

Hide GUI label on press 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges