How to set a gameobject to an exact length in unity

I created a workaround function to convert a specific length into a scale (for anyone who may find this question in the future). Game objects can only have their size changed though scale, but their exact size can be found through the renderer. using a little interpolation you can convert this into a new scale to resize your object to an exact size.

public void newScale(GameObject theGameObject, float newSize) {

    float size = theGameObject.GetComponent<Renderer> ().bounds.size.y;

    Vector3 rescale = theGameObject.transform.localScale;

    rescale.y = newSize * rescale.y / size;

    theGameObject.transform.localScale = rescale;

}

Tags:

C#

Unity3D