Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Question How do you access a Rich text link tag in a Label element?

Discussion in 'UI Toolkit' started by monark, Sep 7, 2022.

  1. monark


    May 2, 2008
    So UI toolkit supports Rich text now and you can format text using tags.

    But how would you implement something like this which works for a standard Text Mesh Pro component
    to find out when the mouse is over a link tag?
    I can register an event to get when the mouse is over the whole label but I want a particular word.

    Code (CSharp):
    1. using UnityEngine;
    2. using TMPro;
    3. using UnityEngine.EventSystems;
    6. [RequireComponent(typeof(TMP_Text))]
    7. public class OpenHyperlink : MonoBehaviour, IPointerClickHandler
    8. {
    9.     private TMP_Text m_textMeshPro;
    10.     void Start()
    11.     {
    12.         m_textMeshPro = GetComponent<TMP_Text>();
    13.     }
    14.     public void OnPointerClick(PointerEventData eventData)
    15.     {
    17.         int linkIndex = TMP_TextUtilities.FindIntersectingLink(m_textMeshPro, Input.mousePosition, null);
    18.         if (linkIndex != -1)
    19.         {
    20.             TMP_LinkInfo linkInfo = m_textMeshPro.textInfo.linkInfo[linkIndex];
    21.             Application.OpenURL(linkInfo.GetLinkID());
    22.         }
    23.     }
    24. }
  2. HugoBD-Unity


    Unity Technologies

    May 14, 2018
    Hi @monark!

    This thread covers what's currently supported for interactions with fragments of text.
    monark likes this.