- Home /
How do you auto scale the space between Gui Buttons?
I was able to make it so that the buttons scale relative to the size of the screen but the problem is that when they do change size so does the position and spacing. How do I rectify this, I'm pretty new at this and would appreciate any help.
// Update is called once per frame
void Update()
{
horizontalRatio = Screen.width / BASE_WIDTH;
verticalRatio = Screen.height / BASE_HEIGHT;
}
Rect setPositionAndSize(float x, float y, float w, float h)
{
x *= horizontalRatio;
y *= verticalRatio;
w *= horizontalRatio;
h *= verticalRatio;
return new Rect(x,y,w,h);
}
void OnGUI()
{
if (GUI.Button (setPositionAndSize(sbposx, sbposy, sbbottonw, sbbottonh), SwatbotTexture, ""))
{
}
if (GUI.Button (setPositionAndSize(bbposx, bbposy, bbbottonw, bbbottonh), BeakbotTexture, ""))
{
}
}
}
Comment
if you want only the position to change dont do this
w = horizontalRatio; h = verticalRatio;
ins$$anonymous$$d jus return w and h as it is...
Actually im not getting what exactly you are looking for?!
oh sorry, I'm trying to make it so that when the size changes the spaces between the two buttons are still the same
Best Answer
Answer by gimoj · May 09, 2014 at 07:21 AM
okay nevermind, I figured it out. I simply had to add to the pos of the first button for the pos y of the second. Thanks!