Hello, I am using text mesh pro GUI to get certain words that are shown on screen, but I would like to be able to get the location of those certain words, and cant figure out how too. Also really struggling to find good documentation on this.
I have managed to get the info on what word is clicked, but how do i go about getting its position in the world from there? The code I am using to get the word clicked info is
if (Input.GetMouseButtonDown(0))
{
intwordIndex = TMP_TextUtilities.FindIntersectingWord(textElement, Input.mousePosition, null);
Debug.Log(wordIndex);
Because I am struggling to find documentation, I have check all the methods that show when I type in TMP_ class name. However I have not came across anything that I think could do what I am wanting.
There is some helper class to do this in TMPro… I always forget if it is called layout or measurement or positioning. Hang on a sec while I look.
I think it’s something in here? TMP_TextUtilities Check around and see what those do… there definitely is something that lets you find where it all goes…
Did you ever end up finding anything? I’m currently trying to acomplish the same thing you were, finding the worldposition of a particular word in a string of text.
This might help anyone looking into this.
The characterInfo array has the position info for individual characters in TMP_Text space, on another hand, you can get each word first and last characters using TMP_WordInfo struct. Putting these together, you can get each word rect info in world space after translating character position using tmp_text.transform.TransformPoint:
foreach (var wordInfo in tmpText.textInfo.wordInfo)
{
if (wordInfo.characterCount == 0)
continue;
var firstCharInfo = tmpText.textInfo.characterInfo[wordInfo.firstCharacterIndex];
var lastCharInfo = tmpText.textInfo.characterInfo[wordInfo.lastCharacterIndex];
var wordLocation = tmpText.transform.TransformPoint((firstCharInfo.topLeft + lastCharInfo.bottomRight) / 2f);
Instantiate(WordMarker, wordLocation, Quaternion.identity);
}