Hi every one, , not how to rescale an object.

i need to know how to obtain the size of an object in pixels, something like gameobject cube 234x123 pixels may be it is easy but i dont know how to do it, i need a script to get the size in pixels of a cube or a botton preferably, and show it in the unity console, it is because i need to know the measures of the textures i need to put in the box or button so that the texture looks good and not to pixeled.
i found here some code like this:

 [MenuItem("Window/ShowSize")]
static void Init()
{
	// Get existing open window or if none, make a new one:
	ShowSize sizeWindow = new ShowSize();
	sizeWindow.autoRepaintOnSceneChange = true;
	sizeWindow.Show();
}

void OnGUI () {
	GameObject thisObject = Selection.activeObject as GameObject;
	if (thisObject == null)
	{
		return;
	}
	
	MeshFilter mf = thisObject.GetComponent(typeof(MeshFilter)) as MeshFilter;
	if (mf == null)
	{return;}
	
	Mesh mesh = mf.sharedMesh;
	if (mesh == null)      
	{return;}
	
	Vector3 size = mesh.bounds.size;
	Vector3 scale = thisObject.transform.localScale;
	GUILayout.Label("Size

X: " + size.xscale.x + " Y: " + size.yscale.y + " Z: " + size.z*scale.z);
}

but this just give me the scale of the object in a show size windows, and that doesn’t work for me.
thanks a lot by the way, im new in unity3d edition =)

The pixel size of an object with a perspective camera varies based on the distance from the camera. In addition, as you change the resolution of the app (as would happen when moving from one mobile device to another), the pixels also change. Typically if you have a specific device and are looking for pixel perfect, you do it in reverse…you pick a pixel size for the texture then setup the environment to display it at or near pixel perfect. If you really want to know the pixel size of an object there is some code in this answer:

Note this calculates the bounds of the mesh of the object, so the results will depend on the rotation of the object. So for example, if you wanted the pixel size for the bottom of the cube, the bottom would need to be axes aligned and facing an axes aligned camera.