I'm wondering how to properly Size my GUI elements, I'm relatively new to scripting GUI. Although it isn't hard, It is quite tricky to get it right.
So the biggest problem I'm having is that on my phone everything looks perfect, the size and the position. But when I tested my game on a friends phone, the GUI was really small.
Currently I use this to get kind off the right size:
void Update ()
{
float ButtonWidth = 0.3f * Screen.width;
float ButtonHeight = 0.25f * Screen.height;
}
void OnGUI()
{
if(DisplayScreen)
{
if(GUI.Button(new Rect(Screen.width/2 - ButtonWidth/2, Screen.height/2 - ButtonHeight/2, ButtonWidth, ButtonHeight), "Start game"))
{
}
if(GUI.Button(new Rect(Screen.width/2 - ButtonWidth/2, Screen.height/2 + 10 + ButtonHeight/2, ButtonWidth, ButtonHeight), "Statistics"))
{
}
}
}
But because not every button is the same size or placed on the same positions this could become a very annoying and it feels very inefficient.
So I was wondering if there is a better way to make the GUI sizes work properly on different devices?
↧