How do I shrink a cube with scripts?

I’m making a 2D game and a character needs to crouch. The material Sets to a picture of someone crouching, but the box stays the same size. How do I make it shrink to the size of the image file of the texture? If imposible, how else can i make a 2d character made from one shape crouch?

Take a look at transform

You would need to adjust the value using the localscale property of the transform.
i.e

transform.localScale.y = 0.5;