Search code examples
unity-game-enginescaledimensiongameobject

Unity, Relative dimensions of gameobjects


I saw some documents saying that there is no concepts of length in Unity. All you can do to determine the dimensions of the gameobjects is to use Scale.

Then how could I set the overall relative dimensions between the gameobjects?

For example, the dimension of a 1:1:1 plane is obviously different from a 1:1:1 sphere! Then how could I know what's the relative ratios between the plane and the sphere? 1 unit length of the plane is equal to how much unit of the diameter of the sphere!? Otherwise how could I know if I had set everything in the right proportion?


Solution

  • Well, what you say is right, but consider that objects could have a collider. And, in case of a sphere, you could obtain the radius with SphereCollider.radius.

    Also, consider Bounds.extents, that's relative to the objects's bounding box. Again, considering the Sphere, you can obtain the diameter with:

    Mesh mesh = GetComponent<MeshFilter>().mesh;
    Bounds bounds = mesh.bounds;
    float diameter = bounds.extents.x * 2;