- Home /
GUILayout.Button scales texture wrong
Hi,
sorry if this was already asked but I did not find anything.
I am trying to convert my gui into using the GUILayout class, however the textured button behaves differently.
This is the code:
void OnGUI () {
GUILayout.BeginArea(new Rect(0,0,128,128));
GUILayout.Button(btnTexture);
GUILayout.EndArea();
GUI.Button(new Rect(128,0,128,128), btnTexture);
}
In theory both buttons should look the same, however this is the result:
The button starts acting up as soon as its size is smaller than the texture to draw. Is there a way to fix this?
greetings
What size does your btnTexture has? Should that texture be a button background? If so why don't you use a gui skin?
512x256, I know that this is way too big, but this is a general test. While this button won't be an image button I have others that will, so I cannot use a skin for that.
I have now tried various button dimensions with texture dimensions. The problem seems to be that the button's height is always the height of the texture no matter how small or big it is scaled inside the button.
The same problem occurs when I use a selection grid.
Take a look at GUILayoutOptions
.
Also note that GUILayout
is always slower than plain GUI
, so if you have the interface you like using GUI
please don't convert it to GUILayout
I tried them and while they do restrict the button's size they have no effect on the scaling issue.
I have an interface yes, but it does not ajdust like it would with the layout. Oh well, I guess I will have to program some sort of manager myself.
greetings
Your answer
![](https://koobas.hobune.stream/wayback/20220613112248im_/https://answers.unity.com/themes/thub/images/avi.jpg)