If anyone is trying to find a simple solution, this one is very functional.
My text example with two clickable links:
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:
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);
}
}
}
}