- Home /
Dimensions of a Cube
How do I find the dimensions of a cube in terms of (X, Y, Z, Width, Height, Depth)?
Answer by smallbit · Jul 29, 2014 at 02:06 AM
X,Y,Z is stored in vector3 field gameObject.transform.position(.x, .y , .z) (dependent of where pivot point is) width,height,Depth is in gameObject.transform.localScale(.x,.y,.z)
If you want to get them in your nomenclature (X, Y, Z, Width, Height, Depth) like for rect, You have to have the pivot point in the corner. The default unity cube will have it in the center. Hence you will need to shift by half of scale, For instance your X will be gameObject.Transform.position.x - gameObject.Transform.localScale.x/2 etc.
Answer by HolBol · Jul 29, 2014 at 01:40 AM
Transform.Scale should do it, surely? If you're using a unity primitive, taking unity units as meters, a standard cube is 1m x 1m x 1m.