[SOLVED]get dimensions of object..

Hi,

Dumb question.

How do I get the global dimensions of an object via C# script?

Is it transform.localScale? Because that doesn’t seem to work.

I am trying to write a script to position prefabs in an 8x8 matrix using a for loop that positions each new prefab instantiation in a translated poition from an initial object, where the translation is a multiple of initial objects width and depth. Given the initial object in the script, I am struggling to get the appropriate width and depth values to translate the additional prefabs such that they are adjacent to each other.

All advice welcome.

Cheers,
Tom

Using transform.lossyScale you can find the scale relative to the original model. For the built-in cube, sphere, capsule, cylinder, and plane, this will yield values in meters. For everything else, it depends on how you originally scaled it in your modeling program : P

Thanks cjcurry,

I take it that means I should scale my width/depth from localscale by the mesh width/depth. Is there any way to get the global dimensions of the mesh in unity?

Tom

Like I said, lossyScale returns global values, but only based on the original (ie unscaled) dimensions of the mesh. If you built your mesh in a modeling program to be 5 units long and in Unity scaled it to be 10 units long, lossyScale would tell you it’s scaled by a factor of 2.

If you don’t know your original size, then lossyScale won’t help, and you’ll be left with only integrals and a lot of other fancy calculus to help you :wink:

Awesome.

Thanks man. I have finally got it going using unity cube stuff and localScale.

Thanks for ur help