Making a cube crouch

I’m just getting started with Unity and I want to make sure I know the best practice for this kind of manipulation.

I have a cube, when the player presses crouch I want to instantly reduce it’s height by half.

I am reducing the scale like so:

	void Start () {
		normalScale = gameObject.transform.localScale;
		duckScale = new Vector3(normalScale.x, normalScale.y / 2f, normalScale.z);
	}
	
	void Update () {
		
		if(Input.GetButtonDown("Duck"))
		{
			Debug.Log("Duck!");
			if(!isDucking)
			{
				isDucking = true;
				gameObject.transform.localScale = duckScale;    				
			}
		}
		
		if(Input.GetButtonUp("Duck"))
		{			
			if(isDucking)
			{
				gameObject.transform.localScale = normalScale;
			}
			isDucking = false;
		}
		
	}

This works fine, but the cube is then partially raised off of the ground due to it’s origin being at it’s center. What is the best way to alter it’s y position in this case so that the bottom of the cube stays on the ground?

Thanks

You can put the cube inside an empty parent and align it so it’s base is at the parent’s coordinates, then when you scale the empty container, the cube will stay attached to the floor.