Scaling GUI text box

I have a GUI text box that originally used these parameters and looked correct:

GUI.Box (Rect (52, 52, 258, 78), Throttle_Foreground, throttleGuiStyle);

I want the box to scale horizontally based on a variable, but remain the same vertically. I replaced the third parameter with the variable (which resolves to a percentage like .63) like this:

throttleWidth = 258 * (GlobalVariables.gSpeedTarget / GlobalVariables.gThrottleMax);
	
GUI.Box (Rect (52, 52, throttleWidth, 78), Throttle_Foreground, throttleGuiStyle);

The box scales in both dimensions rather than just horizontally. I’m not sure why. Is there something in the code I should change?

Thanks!

Are you getting any error messsages with this?

Nope. It just scales vertically and horizontally instead of just horizontally.

What is happening here is that the texture image is being scaled, keeping height and width in proportion. If you try using the same code but without the GUIStyle, you’ll see the outline of the box with the image scaling inside it.

If you want the image to stretch, you’ll need to use GUI.DrawTexture instead of GUI.Box.

That did the trick. Thank you! :slight_smile: