Instantiating at a position relative to another object?

Hey. When Instantiating an object, how can I use Bounds.size to have the objects edges be at the edge of another object when it spawn? For example, if I have a cube I want to spawn and a rectangle somewhere in the scene. I want to spawn the cube so that its edge is at the edge of the rectangle? Thanks

If you are using C#, then try something like this:

Instantiate(cube, new Vector3((rectangle.transform.position.x - (rectangle.transform.localScale.x/2)) - (cube.transform.localScale.x/2) , rectangle.transform.position.y, rectangle.transform.position.z), Quaternion.identity);

if you want it on the x side of the rectangle.

haven’t tested, if it works tho…