- Home /
Unable to stretch texture over entire button
Hello,
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,
weaponBoxWidth,
weaponBoxHeight), (Texture)tempMasterWeaponList[i].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:
Setting the texture type as a GUI.
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.
Create the texture at exactly the same size as button. Almost, but doesn't stretch over whole button.
Can anyone help? Thanks a lot!
Answer by Thibaut D · Feb 07, 2013 at 02:26 PM
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, "");
Thanks for the help. Good to have another solution to the problem. At the moment I'm just using a lot of GUI Styles, which also stretches textures properly.
I tried that with GUI.Window ins$$anonymous$$d of button and it didnt work
Your answer
Follow this Question
Related Questions
Stretching Texture2D 1 Answer
scaling behaviour of the standard box texture? 0 Answers
GUI texture size doesn't match control set with the same size 1 Answer
Touchscreen for unity 2 Answers