Pixels per meter is 1 in the sprite collection.
My sliced sprite is 100x100 with 2 pixel border. I have a hard time adding the background and getting the size.
As you can see from below code I kinda hacked it to work, but of course now I need to add boxes exactly after each other and this fails.
If at all you have the time, I would appreciate some pointers. Main issue is probably if the sliced sprite is 100x100 with a 2 pixel border how do I make it fit the size of my text mesh?
Thanks in advance
Odin
public static void AddBackground(GameObject textObject)
{
// Instantiate object
GameObject instance = Instantiate(Resources.Load("Borderback", typeof(GameObject))) as GameObject;
// Get camera
Camera cam = tk2dCamera.Instance.camera;
instance.transform.position = textObject.transform.position;
instance.transform.position = new Vector3 (instance.transform.position.x-10, instance.transform.position.y-6, 1);
instance.transform.parent = textObject.transform;
Bounds extends = textObject.GetComponent<tk2dTextMesh>().GetEstimatedMeshBoundsForString(textObject.GetComponent<tk2dTextMesh>().text);
Vector2 oldDims = instance.GetComponent<tk2dSlicedSprite> ().dimensions;
//Debug.Log (oldDims.x);
float extendsWidth = (extends.extents.x);
Debug.Log (extendsWidth);
float mulFac = 1.0f;
if (textObject.GetComponent<tk2dTextMesh>().text.Length < 3)
{
instance.transform.position = new Vector3 (instance.transform.position.x-12, instance.transform.position.y, 1);
mulFac = 1.5f;
}
instance.GetComponent<tk2dSlicedSprite> ().dimensions = new Vector2 ((73 * (extendsWidth / oldDims.x)+10)*mulFac , extends.extents.y*1.5f);
}