3d cube Wrapper around an 3d object

How do you go about scaling a box, with a script, to be the same size of the GameObject you are going to Instantiate?

For example if you look at the image

The green box illustrates the size of the cube which should be the size of the spaceship and if select a different GameObject to be placed the size should dynamically grow prior to placing the object.

I’ve tried the *.transform.localScale and working with the bounds min and max values but nothing seems to work.

How would i go about doing the scaling of the cube?

Hi, @tanoshimi

Bounds bounds = selectedObject.GetComponent<Renderer>().bounds;

box.transform.position = new Vector3(bounds.center.x, bounds.center.y, bounds.center.z);
box.transform.localScale = new Vector3(bounds.size.x, bounds.size.y, bounds.size.z);