Search Unity

TextMesh Pro How move position of text box based on word positions in Text Mesh Pro

Discussion in 'UGUI & TextMesh Pro' started by Payamn, Feb 15, 2018.

  1. Payamn

    Payamn

    Joined:
    Apr 2, 2017
    Posts:
    1
    Hello

    sorry if this was answered already. But basically developing a reader app which will scroll text to a specific position on the page. Each word will hit that particular position for a certain duration.
    Using TextMesh Pro to achieve this.
    So I need to first identify the position of each word so I can then move the text object so that word is centred on the target position. Could you please direct me to the correct syntax for doing this having trouble finding specific word positions.

    Thanks
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    When a text object is generated, the TMP_Text.textInfo gets populated. This TMP_TextInfo class contains several structures with information about every character, words, line, links, and even the mesh data of the text object.

    To achieve what you want, you will need to use the information contained in this textInfo and more specifically the textInfo.wordInfo[wordIndex].

    To learn more about how to access this information, find the TMP_TextInfoDebugTool.cs which is included in the "TextMesh Pro/Examples/Scripts/..." folder and add this script onto any TMP text object.

    I created this script to help me visualize the information contained in the textInfo. This script provides a good example of how to access the information contained in the textInfo.

    You should also look at Example 12a which fires events when mousing over characters, words, lines, etc... this too was implemented by using the information contained in the textInfo.