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 =)