Find screen position of a specific word in a RichText?
I have a RichText displayed with a full text in it. Without clicking on the screen I want to generate a new game object exactly on top of specific words in the RichText.
How would I get the exact screen location of a specific word within a RichText?
Thanks a lot!
Answer by pfreese · Aug 30, 2016 at 08:54 PM
The UI.Text component exposes a TextGenerator property (http://docs.unity3d.com/ScriptReference/UI.Text-cachedTextGenerator.html) that you can use to find the position of generated glyphs. These positions will be relative to the gameObject with the Text component, so you'll need to do some additional transformation to get the screen position.
Could you please give a bit more detail on this? I am not quite sure I understand how to use it.
Thanks!
When adding tags in the text, even though they are not displayed, it seems to have an impact on the values returned for the positions... how can this be possible as the screen content is not changing?
I am probably not using this right...
Your answer
Follow this Question
Related Questions
how can i set a sprite to a fixed position? 1 Answer
Text Over Object That Faces Camera 0 Answers
How to properly update caret position when modifying TMP input field with Rich Text ? 0 Answers
How to set the position of these Texts ?? 0 Answers
Problem when respawning a rigidbody in the desired position using rigidboy.position. 0 Answers