2D Toolkit Forum
2D Toolkit => Support => Topic started by: narenski 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
-
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 ;
}
}
-
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.