How to scale an object height on top side only?

I did this code but it scales up on both top & bottom side, But I need to scale on top side only.

Check the image please.

Vector2 tempSize;

	void Update () {
		tempSize = transform.localScale;
		tempSize.y += Time.deltaTime;
		transform.localScale = tempSize;
	}

The object is scaled around its pivot. You can either design your object to have the pivot on the bottom, or move it upwards as you scale it.
The pivot is where the ‘position’ widget is seen in the editor (but you must have the handle position set to ‘pivot’, not ‘center’). If, for example, you are rendering the unity’s default cube mesh (which has a pivot in the middle), scaling the cube renderer will make it grow in all directions. For such case, try this:

  • Create an empty gameObject on the ground level (This object will act as a pivot)
  • Create a child object with your renderer. Move the renderer in desired position, with respect to the ‘pivot’ object. Move it upwards, so it looks like the cube is standing on the ground
  • Now, scale the pivot object. The child cube will be scaled and moved (as it’s local position is being scaled too)

The code is same, just set the Image pivot to bottom.