Search Unity

Unity UI Displaying text horizontally by character sets, not getting accurate distribution

Discussion in 'UGUI & TextMesh Pro' started by maertsoi, Feb 7, 2023.

  1. maertsoi

    maertsoi

    Joined:
    May 27, 2012
    Posts:
    5
    I'm having an issue where text I've parsed is not being evenly distributed along the X axis, but it appears to only be happening for character sets that are 2 or more characters. I've included an image of how it's being displayed vs. how it should be displayed. The code itself is pretty minimal as well.

    I update the next items X value based on the width of the current item. I don't see where this is going wrong.


    Code (CSharp):
    1. // startXPos initialized to 0f
    2.  
    3. // ...
    4. for(int cur_word = 0; cur_word < senData.Length; cur_word++) {
    5.             // put the text in the UI element
    6.             newContainer[cur_row, cur_word].GetComponent<TextMeshProUGUI>().text = text_data;
    7.             // force it's position
    8.             newContainer[cur_row, cur_word].GetComponent<RectTransform>().anchoredPosition = new Vector3(startXPos, 0f, 0f);
    9.             // get ready for the next one
    10.             startXPos += (newContainer[cur_row, cur_word].GetComponent<RectTransform>().rect.width);
    11.         }
     

    Attached Files: