I tried writing an Editor which would allow the user to align the min, max or center points of the Collider.Bounds, Mesh.Bounds and Renderer.Bounds of one game object with another’s along any of the 3 world axes. After I finished writing the code, I then found out that the Bounds properties are pretty much either read-only values or simply unchangeable for some reason or other. So now I pose this question: is a Bounds Aligner Tool even a feasible idea to begin with? Or is manually aligning colliders and moving transforms truly the only way to align objects and components with other objects and components?
Bounds is a struct which means it is passed by value, if you change it, you have to pass it back again to where you “took” it from.
Bounds a = new Bounds ();
b = a;
b.center = Vector3.one;
//Now 'a' won't be equal to 'b' since you have only modified the copy 'b' has.
//So let's pass it back.
a = b;
//Now a == b again.
In your case it seems like you want to:
- Calculate difference between bounds.center and transform.position;
- Align bounds.
- Set transform.position = bounds.center+difference.