Hello Guest

Author Topic: TextMesh character position and size  (Read 3878 times)

narenski

  • Newbie
  • *
  • Posts: 2
    • View Profile
TextMesh character position and size
« on: April 16, 2014, 02:42:08 pm »
Hi
I'm looking for a way get Textmesh character height and width printed at screen?
Is it possible?
 thx

narenski

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: TextMesh character position and size
« Reply #1 on: April 16, 2014, 06:08:23 pm »
I find how to get a size. is by calling mesh.renderer.bounds.size;
this is the code. the characters are not a the good position: I'm using a tk2dCamera
I don't know why but when id devide the bounds.size / 10 it's seem working a little. But i have not the good x position.
Can anyone help me::

    private void DoText()
    {
        float position = 0;
        foreach (var c in "New TextMesh")
        {
            var go = (UnityEngine.GameObject)UnityEngine.GameObject.Instantiate(UnityEngine.Resources.Load("Prefabs/TextMesh"));
            var mesh = go.GetComponent<tk2dTextMesh>();
            mesh.text = c.ToString();
             var bounds = mesh.renderer.bounds;
            go.transform.position = new Vector3(position, go.transform.position.y, go.transform.position.z);

            position += bounds.size.x / 10 ;
        }
    }
« Last Edit: April 16, 2014, 06:47:36 pm by narenski »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: TextMesh character position and size
« Reply #2 on: April 17, 2014, 03:04:19 am »
renderer.bounds = the size of the whole text mesh, not one character. There isn't a way to get to each character in there, if you need this you'll have to customise the code. The relevant bit of code is in tk2dTextGeomGen.SetTextMeshGeom - this is the code that generates the geometry for the text mesh based on characters. If you wish you can save the position of each character here.