The game I’m working on will be playable on iPhone, iPad and Android devices. Yet the only issue we’re facing at the moment is the placement of buttons in the menu, as every device has a different resolution. So I thought making it dynamic as possible by calculating a percentage would fix it, sadly it does not. Here’s what I did:
private void Start ()
{
SetButtonPositions();
}
private void SetButtonPositions()
{
float screenWidth = Screen.width;
buttonPositionWidth = screenWidth / 2;
float screenHeight = Screen.height;
buttonPositionHeight = (screenHeight - 400) / screenHeight;
}
private void OnGUI()
{
guiStyle = GUI.skin.label;
if (GUI.Button(new Rect(buttonPositionWidth - (textureStartButton.width / 2), Screen.height * buttonPositionHeight, textureStartButton.width, textureStartButton.height), textureStartButton, guiStyle))
{
Debug.Log("start pressed");
Application.LoadLevel("menu_levels");
}
if (GUI.Button(new Rect(buttonPositionWidth - (textureAppStoreButton.width / 2), Screen.height * buttonPositionHeight + 125, textureAppStoreButton.width, textureAppStoreButton.height), textureAppStoreButton, guiStyle))
{
Application.OpenURL("http://apple.com/");
}
}
The width works well, as it has to calculate the absolute middle. But then the height, that actually is causing the problem here. I am trying to let it calculate a percentage so no matter what the screenHeight is, it should always be placed nicely.
Is there any way to place the buttons based on a percentage? This would remove a lot of the issues I’m having with the different resolutions.