How do you stretch a texture2d to fill an entire button (with button being larger than the texture2d)?
How do you do this if the texture2d is square, and the button is rectangular - how do you get it to stretch the entire long length of the rectangle?
To make a GUIStyle to stretch it’s background image you:
btw. A GUISkin is just a collection of GUIStyles (and some general settings). Every GUI element is drawn with a GUIStyle. A GUISkin is just an easy way to exchange all styles at once.
when you import images unity resizes it to the nearest power of two…
so click on your image, go to your inspector and then change ‘Texture Type’ to ‘GUI’ .
and now give that texture to your button like this and it works…
GUI.Button(new Rect(Screen.width/2-100, Screen.height/2, 200, 50), texture, btnStyle);
btnStyle is a custom GUI style… just check ‘Stretch Width’ and ‘Stretch Height’