Unable to stretch texture over entire button


Having some difficulty getting a texture to stretch over an entire button. Have checked the other threads, but nothing has worked so far.

I’m building a GUI screen to allow players to buy weapons, and I want the weapon texture on the buttons. The texture fills the button vertically, but not horizontally.

This is how I’m loading the buttons. The texture comes from an array of objects

if(unlocked == true)


		GUI.Button(new Rect(topButtonSpacing + weaponBoxWidth + (topButtonSpacing * (i+1)) + (weaponBoxWidth * i),
		(vertSpacing * 3) + topButtonHeight, 
		weaponBoxHeight), (Texture)tempMasterWeaponList*.GetWeaponImage(), "stretchButton");}*

stretchButton is a custom style in a GUI Skin. It has no border, fixed h/w are 0, stretch h/w are ticked.
Other things I’ve tried:
1. Setting the texture type as a GUI.
2. Creating a custom GUI Style for each button, with the desired texture as the background. This does actually stretch the texture properly, but it’s an extremely unwieldly solution given that there are multiple states for each button, and a good number of weapons.
3. Create the texture at exactly the same size as button. Almost, but doesn’t stretch over whole button.
Can anyone help? Thanks a lot!

As far as I renember GUIButton with texture try to keep your original texture ratio. That’s mean hat if your button as a different ratio, the button will not be totaly fill with the texture.

I Don’t renember if you can do it by editing the GUI skin (On a skin look at “button” and try to check Stretch Width and stretch Height).

An other solution. A little crapy solution. Replace your button with a DrawTexture AND a BUTTON. DrawTexture by default stretch your texture to fill the rect entierly.
For exemple :

GUI.Button(MyRect, MyTexture);

Can be replace with

GUI.DrawTexture(MyRect, MyTexture);
GUI.Button(MyRect, "");