# Clickable link within a text

**URL:** <https://discussions.unity.com/t/clickable-link-within-a-text/795397>\
**Category:** TextMesh Pro\
**Tags:** UGUI, TextMesh-Pro, Text\
**Created:** [June 11, 2020, 5:30pm UTC](https://discussions.unity.com/t/clickable-link-within-a-text/795397 "2020-06-11T17:30:50Z")\
**Posts on this page:** 1\
**Showing post:** 36

<div class="post-metadata">

**Author:** ![sandolkakos](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/sandolkakos/32/885485_2.png) [@sandolkakos](https://discussions.unity.com/u/sandolkakos)\
**Post date:** [January 8, 2025, 11:29pm UTC](https://discussions.unity.com/t/clickable-link-within-a-text/795397/36 "2025-01-08T23:29:55Z")

</div>

If anyone is trying to find a simple solution, this one is very functional.

My text example with two clickable links:

```auto
Stay tuned to our social media for all the updates:
<color=#00FFFF><link="https://www.instagram.com/orgames_net">- Instagram: @OrGames_net</link></color>
<color=#00FFFF><link="https://www.x.com/orgames_net">- X: @OrGames_net</link></color>

```

You just have to drop this MonoBehaviour in your text mesh pro gameObject:

```cs
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;

namespace YourNameSpace
{
    [RequireComponent(typeof(TMP_Text))]
    public sealed class TMP_HyperlinkHandler : MonoBehaviour, ISerializationCallbackReceiver, IPointerClickHandler
    {
        [SerializeField]
        private TMP_Text textComponent;
    
        public void OnBeforeSerialize()
        {
            if (textComponent == null)
            {
                textComponent = GetComponent<TMP_Text>();
            }
        }
    
        public void OnAfterDeserialize() { }
    
        public void OnPointerClick(PointerEventData eventData)
        {
            int linkIndex = TMP_TextUtilities.FindIntersectingLink(textComponent, eventData.position, null);
    
            if (linkIndex == -1)
            {
                return;
            }
    
            var linkInfo = textComponent.textInfo.linkInfo[linkIndex];
            string link = linkInfo.GetLink();
    
            if (link.StartsWith("https://") || link.StartsWith("www."))
            {
                Application.OpenURL(link);
            }
        }
    }
}

```

---

_[View the full topic](https://discussions.unity.com/t/clickable-link-within-a-text/795397)._
