- Home /
Draw Button with GUITexture which looks like Unity button
Hey Guys,
I was wondering how unity draws buttons (if drawn in the OnGUI function). When I look into a GUI skin, the default button background is an image with only 12x12 pixels. I now want to use the same image with a GUITexture. But because the size is 12x12 pixels, the texture becomes ugly and pixelated if I increase the size of the GUITexture. So how Unity is able to draw a good looking button from this small image, no matter how big you want the button? And how can I do the same with a GUITexture?
Thanks for your help.
Answer by poncho · Jan 31, 2014 at 08:39 PM
you could use a 12x12 pixels to build a x*y pixels button, you could make a function to get the corner 4x4, the mids 4x4, 1x4 or 4x1 and the center 4x4 to resize in any texture size you need, some getpixels, and a local texture2d would do the trick, the corners would stay the same, but the mids and center will repeat the number required to close the gaps, just a little math here and there and you are done
Thank you for your answer. Yesterday I tried it again by myself and I found a solution, very similar to yours. A GUITexture has the properties Left Border, Right Border, Top Border and Button Border. There you can define the pixels which will never be scaled. So I set every one of them to 5 and now it looks exactly like a normal button.
If someone want to do the same, here you can find the official skins of unity, including the texture for the button.
well, never thought about unity would help us out in that level, great thing though, I tried helping you and you helped me back, Thanks Scopus
Your answer
Follow this Question
Related Questions
Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer
2 Position GUI Texture Rocker Switch 0 Answers
How to control GUITextures within a single C# script? 1 Answer
GUI 2D Bounding Box 1 Answer
Move GUI elements. 0 Answers