Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Place text next to last character

Discussion in 'UGUI & TextMesh Pro' started by Rachan, Aug 20, 2023.

  1. Rachan

    Rachan

    Joined:
    Dec 3, 2012
    Posts:
    728
    Hi there

    I'm using Legacy Text from Unity because my project is very old and I don't want to mess up,

    So, I want to place a text next to other text at the last character

    such as

    Place text2 next to text1, But place at the last character of text1

    is this possible?

    Thanks!!!
     
  2. Klausbdl

    Klausbdl

    Joined:
    Aug 12, 2013
    Posts:
    60
    You want to combine just the strings or two whole Text game objects? Please describe in more detail.

    For the first: How to insert one string into another using Insert() in C# (educative.io)

    For the later: I imagine you would need to define a length for each character (because some are wider than others: - i u l m n j / : ~ 1 3 ) and then run a loop through this string and add the corresponding length to a total variable. At the end you have the correct length of your text and you can now position the Text2 object at the Text1.position.x + the total length of the characters.
     
    Rachan likes this.
  3. Klausbdl

    Klausbdl

    Joined:
    Aug 12, 2013
    Posts:
    60
    If you want to use anchors, you can use this component on your first Text object: upload_2023-8-20_20-2-3.png

    And then have the second Text object anchored to the left:
    upload_2023-8-20_20-3-23.png

    Place the X pivot at the left so its easier to control
     
    Rachan likes this.
  4. Rachan

    Rachan

    Joined:
    Dec 3, 2012
    Posts:
    728
    Thank you very much!!!