text mesh pro
I am trying to add hyperlinks in my text by using text mesh pro asset , I have added the tag for it and the Scripts TMP_text_Selector_B to it and TMP_text_Info Debug to it and have added different ids to each link textx, now the problem is that when I click my other texts also it is opening the other links if some one is having a solution for how to add hyperlinks for multiple texts in a line it would be of great help
Answer by Siniarski · Jul 06, 2017 at 07:02 AM
Was figuring this out today as I was running into similar issues. Here is an example of the script attached to the same gameObject that has my TextMeshProUGUI component.
using UnityEngine;
using UnityEngine.EventSystems;
using TMPro;
public class MyTextMeshLinkHandler : MonoBehaviour, IPointerClickHandler
{
TextMeshProUGUI textMeshPro;
Canvas canvas;
Camera camera;
void Awake ()
{
textMeshPro = gameObject.GetComponent<TextMeshProUGUI> ();
canvas = gameObject.GetComponentInParent<Canvas> ();
if (canvas.renderMode == RenderMode.ScreenSpaceOverlay) {
camera = null;
} else {
camera = canvas.worldCamera;
}
}
public void OnPointerClick (PointerEventData eventData)
{
int linkIndex = TMP_TextUtilities.FindIntersectingLink (textMeshPro, Input.mousePosition, camera);
if (linkIndex != -1) {
TMP_LinkInfo linkInfo = textMeshPro.textInfo.linkInfo [linkIndex];
switch (linkInfo.GetLinkID ()) {
case "id_1":
Application.OpenURL ("http://answers.unity3d.com");
break;
case "id_2":
//Do something else
break;
}
}
}
}
And the content in the Text Input Box for your TextMeshProUGUI component would have something like this.
Hello, I get help from <link="id_1">AnswersUnity</link> and this <link="id_2">Does something else</link>
Just a side note this worked on desktop and iPhone too.
OH $$anonymous$$AN, YOU $$anonymous$$ADE $$anonymous$$Y DAY, I LOST AROUND HOUR JUST GETTING -1 EVERY TI$$anonymous$$$$anonymous$$ WHY IT SHOULD BE NULL?
Your answer
Follow this Question
Related Questions
How to change the text inside UI>Text 1 Answer
Unity 5 - Does anyone know how to scale the text in the UI? 1 Answer
CachedTextGenerator no longer has any character info in Unity 5.3 0 Answers
How do you prevent canvas text from clipping into 3D models? 1 Answer
Resizing font by scale according to screen size, (More complicated than you might think) 1 Answer