Take the x direction of size as an example
1:gameobject.renderer.bounds.size.x;//The result of this value really reflects the size of the model that has meshrenderer this component. No need to multiply localscale.x.
2:gameobject.getcomponent<meshfilter> (). mesh.bounds.size.x;//gets the mesh of the original model through Meshfilter, which returns the size of the original mesh.
To get the size of the model you also need to multiply the model's localscale.x.
That is:gameobject.getcomponent<meshfilter> (). mesh.bounds.size.x*gameobject.transform.localscale.x;
3: Add collider to the object, then use XXX.collider.bounds.size;
This does not necessarily respond well to the size of the object, and the bounds obtains the outer rectangle of the object. And this outsourced rectangle has the same x, Y, z and world coordinates. Therefore, if the object has a rotation, the size obtained cannot reflect the true size of the object, just the size of its outsourced rectangle ...
such as: Get the size of the terrain
Terrainwidth = terrain.collider.bounds.size.x;
Terrainlength = terrain.collider.bounds.size.z;
Terrainheight = Terrain.collider.bounds.size.y;
4: Code to achieve the size of complex objects (such as the root node does not have Meshfilter,meshrenderer components, objects are composed of many complex irregular small mesh sub-objects) such as: Camera aperture size
When the projection type is perspective, the Fieldofview property represents the degree of the aperture, in the range [1,179]
When the projection type is orthgraphic, the Orthographicsize property is the aperture size in orthogonal mode
U3D Outsourcing team-technology sharing u3d to get the size of the object