Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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
0
Question by EMOTION-THEORY · Jul 25, 2015 at 03:18 AM · c#uiinspectorstring4.6

How to make a single word in a Text object clickable / have hover.

Hey everyone.

As the question suggests, I'd like to know how one might have a single word within a Text element clickable.

An example would be in a lot of MMOs in the chat log, player names can be clicked on to open their profile, or Items can have a tooltip when your mouse is hovered over them.

How would one do this using Unity's 4.6 UI system?

Thanks!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Cynikal · Jul 25, 2015 at 06:51 AM

Not sure if this is doable in Unity's UI. However, it is doable in NGUI.

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 EMOTION-THEORY · Jul 25, 2015 at 06:54 AM 0
Share

Could it be possible by finding the position and size of the word and layering an invisible button over it?

avatar image
0

Answer by m1le · Sep 22, 2015 at 06:15 PM

Hello. I work on clickable string with simple UI, and made this simple solution. Create a big Button for your text to be in. Put your text in TEXT of this button. Store the position of the first letter of your clickable word in the entire text.

In you do this at runtime, wait for an update, and.

 Rect target = new Rect();
                     target.position = new Vector2(YourText.cachedTextGenerator.characters[clickable.index].cursorPos.x,YourText.cachedTextGenerator.characters[clickable.index].cursorPos.y + YourText.cachedTextGenerator.lines[0].height / 2);
                     target.width = Mathf.Abs(YourText.cachedTextGenerator.characters[clickable.index].cursorPos.x - YourText.cachedTextGenerator.characters[clickable.index + clickable.Length].cursorPos.x);
                     target.height = - YourText.cachedTextGenerator.lines[0].height;

This will create a target Rect. Store it in a list of Object, with what you want this clickable to do.

And when player clic on this TextButton.

 PointerEventData eventData = new PointerEventData(EventSystem.current);
 eventData.position = Input.mousePosition;
 
 Vector2 localCursor;
 if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(TextButton.GetComponent<RectTransform>(), eventData.position, eventData.pressEventCamera, out localCursor))
             return;
 
 foreach (Clickable cc in MyListOfClickable) {
 if (cc.target.Contains(localCursor,true)) {
 // Hit this clickable string
 }
 }

My response is late, but maybe can help someone else.

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

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

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

binding properties to UI Text/Image etc 1 Answer

[4.6 - UI] Calling function on button click via script 1 Answer

PlayerPrefs not saving slider value & audio 2 Answers

How do I get the Inspector to show Event boxes when extending Unity objects? 0 Answers

Distribute terrain in zones 3 Answers


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