Search Unity

How to create a custom background in TextMeshPro?

Discussion in 'Editor & General Support' started by Tymianek, Apr 30, 2021.

  1. Tymianek

    Tymianek

    Joined:
    May 16, 2015
    Posts:
    97
    Hey, I want to create a custom background for part of my text.
    I want to display key a player needs to press with other TextMeshPro text like so: upload_2021-4-30_19-30-55.png
    but I want to have a custom image background
    upload_2021-4-30_19-31-15.png
    in the marked area.
    I know I can insert an image glyph, but I would have to prerender all possible keys, which is not ideal.
    How can I achieve it?
     

    Attached Files:

  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,911
    I'd probably do it with separate image components underlaid behind the text. You can use the various CharacterInfo APIs from TMPro to get the exact position/sizing etc. for the characters.

    Or insert the empty image glyph in the text and use separate text components to display the letters on top.