?? Get the size of an object in a Unity3d
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. There is no need to multiply localscale.x.
2:gameobject.getcomponent<meshfilter> (). mesh.bounds.size.x;//obtains the mesh of the original model through Meshfilter , The result returned by this value is the size of the original mesh.
To get the size of the model you also need to multiply the model's localscale.x.
namely:gameobject.getcomponent<meshfilter> (). mesh.bounds.size.x*gameobject.transform.localscale.x;
3: Add collider to the object, then use XXX.collider.bounds.size;
This is not necessarily a very good response to the size of the object, bounds obtained is the object of the outsourcing rectangle.
And this outsourced rectangle has the same x, Y, z and world coordinates. Therefore, if the object is rotated, the resulting size 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 a Meshfilter,meshrenderer component, the object is composed of very many complex irregular small mesh sub-objects)
Such as:
Aperture size of camera
When the projection type is perspective, the Fieldofview property represents the degree of the aperture. Range is [1,179]
When the projection type is orthgraphic, the Orthographicsize property is the aperture size in orthogonal mode
Unity gets Object Size