Hi im making a game that has a hud and im using GUI Textures, but recently i have tested the game on a different screen resolution and my GUI textures have moved from their position i set. I understand why this is happening but i cant seem to get a script to fix my problem. So far i have this
var btexture : Texture;
function OnGUI () {
if (GUI.Button (Rect (20,40,80,20), btexture)) {
}
}
I have had a look on the internet and found some solutions but unfortunately all have been unsuccessful for me one of the solutions i tried was
function OnGUI () {
if (GUI.Button (Rect (ScreenHeight/2 * 20,ScreenWidth/2 * 40,80,20), btexture)) {
}
}
As i say nothing has worked so far so any help would be really appreciated.
Thanks.
Some programs use if statement for the most common resolutions and have it go a certain position. so like 1366x768, 800x600, iPhone size, etc. Or you can make a function to adjust the size depending on the resolution with simple numbers, which alone is frustrating, but is better focusing on the common resolutions.
Actually, you could also do the center of the screen take the difference on the screen sizes height and length. Then subtract the position by the length of your GUI text object.
assuming 800x600
screenHeight = 800 //by UNity’s Screen.Height
centerHeight = 800/2
differenceBetweenHeight = screenHeight - centerHeight // this would bee 400
Place GUI centerHeight + differenceBetweenHeight // which would put this below the screen and one pixel being exactly at the max height of the screen. So just take the difference of the height of the Text ** this part will be trial and error **
so… New placement of GUIText centerHeight + differenceBetweenHeight - 20