- Home /
Match a GameObject's size to another's?
I was wondering if it is possible to have a GameObject scale to the size of a smaller object. I have 48 planets for my game and they're all different sizes but when brought into the scene they need to be made the same. Any suggestions?
You could procedurally grow or shrink an objects until the bounds match. Easiest way I can think of.
Answer by BiG · Jul 21, 2015 at 09:14 AM
Yes, you can use Bounds.size. Using C#, you can retrieve the size of an object like this:
Vector3 sizeCalculated = GetComponent<Renderer>().bounds.size;
Then, scale the "new" object this way:
transform.localScale = sizeCalculated;
Hope this could be a good starting point.
Answer by Requiem36 · Jul 21, 2015 at 09:16 AM
If your planets are the same gameObject, setting the scale of each planet to the same value will do it. Otherwise, you could use the mesh of your planet's bounds to know the min/max point and compute the factor you should apply to the size to normalize them.
See http://docs.unity3d.com/ScriptReference/Mesh-bounds.html
Your answer
Follow this Question
Related Questions
What is the difference between these, and how do I fix it. 2 Answers
How do you change size of an object by its units rather than scale? 1 Answer
actual size of an object 2 Answers
Positioning gameobjects by a corner, not by center 0 Answers
How to align the bottom of a GameObject with the ground? 1 Answer