- Home /
Get Position of a specific letter in UI Text containing line breaks
I'm trying to get the position of a specific letter in my UIText by using the textGenerator vertex method describe here: https://answers.unity.com/questions/1221847/get-position-of-specific-letter-in-ui-text.html.
This method works fine unless the UI Text contains line breaks, either from hitting enter in the inspector's rich text editor, or from passing "\n" in a string via code.
With each line break the position returned by the textGenerator for the letter's vertices moves slightly more to the right of where those letters being displayed visually.
What has me totally confused is that the distance moved by each consecutive line break changes, seemingly without a clear pattern.
So how do I get around this issue and find where the letter is being displayed visually.
Example: When trying to get the position of the top left vertex of U. The results are as follows:
String : Vertex.Position.X returned by TextGenerator : Different from where vertex is visually
"Ubot": (5.0) : 0
"\nUbot": (32) : 29
"\n\nUbot": (101): 96
"\n\n\nUbot": (168): 153
"\n\n\n\nUbot": (229): 224
"\n\n\n\n\nUbot": (292): 287
"\n\n\n\n\n\nUbot": (373): 368