Hello Guest

Author Topic: Icon within Textmesh  (Read 4143 times)

benj11

  • Newbie
  • *
  • Posts: 6
    • View Profile
Icon within Textmesh
« on: July 31, 2017, 08:21:51 pm »
I have text to the right of a button that is anchored "Lower Right". I'd like to have an icon to the left of the text. however. the icon doesn't move with the text which causes the text to overlap the icon. Is there a way to anchor the text with the button?

It looks fine when positioned with just two chars: http://imgur.com/6RTP20b
Problems occur with more than two chars (icon needs to move to the left with text): http://imgur.com/wfrJ4mF

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Icon within Textmesh
« Reply #1 on: July 31, 2017, 10:46:44 pm »
Hi,

There isn't a way to do this out of the box, but you can do it programatically -
Code: [Select]
tk2dTextMesh tm;
Vector3 pos = tm.GetComponent<Renderer>().bounds.center - new Vector3(tm.GetComponent<Renderer>().bounds.extents.x, 0, 0);

That gives you the middle left position, you can position the sprite at that position after changing your text.

Alternatively, there may be an easier way to do this. If you add your sprite as a glyph in whatever package you create your font with... you can map it to a character you don't use. For arguments sake if you've bound it to $, you could just type out $ 3000 and it will always be aligned correctly without any code.

benj11

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Icon within Textmesh
« Reply #2 on: August 01, 2017, 05:17:32 am »
Awesome thanks! Was going to do something similar but wasn't sure if there was a way to anchor it :D thanks!