- Home /
placing a GUI.Button at a specific place on multiple screen resolutions
I have looked into this extensively and can not find a solution. I need to place Gui buttons over objects in the scene. I have used screen.width percentage solutions but as the resolution changes more or less of the scene is visible thus changing the percentage that it is from the corner of the screen.
An example of what I've tried{
ButtonPosHor= Screen.width-Screen.width*HorizontalPos ; ButtonPosVert = Screen.height-Screen.height*VerticalPos ;}
Answer by Patel-Sagar · Mar 26, 2014 at 09:40 AM
You can use Camera.WorldToScreenPoint("your object position")
it will set in every resolution and you can set your button depending on this returned position.
Right, keep in $$anonymous$$d that the screenspace y-position is reversed compared to the GUI position. The screenspace has 0,0 at the bottom-left-corner while the GUI space has 0,0 at the top-left-corner. So you need to subtract the y position from Screen.height to get the position in GUI coordinates.
Ah yes! That sounds like it would work. Thank you Patel && Bunny!!
I've used that technique and it works great! thanks again!!
Answer by RedDevil · Mar 26, 2014 at 07:33 AM
I too had this problem the past week but i found the solution on a youtube video + an answer from unity answers:
GUI.Box (Rect (0,0,100,50), "Top-left");
GUI.Box (Rect (Screen.width - 100,0,100,50), "Top-right");
GUI.Box (Rect (0,Screen.height - 50,100,50), "Bottom-left");
GUI.Box (Rect (Screen.width - 100,Screen.height - 50,100,50), "Bottom-right");
Using these the buttons will be on same place and you use Button instead of Box. If you want for example Bottom left more to the left or right you just change the second value of Screen/height -50 to more - or more +.
Thanks but that's not exactly what I am ai$$anonymous$$g to do. You see I don't need them in the same pos on the screen I need them to be over an item in the scene. I was tring to use the screen.width/height percentage method to do it but that still only gets the button over the object for the resolution I set it for.
u can use flag variable for each screen. then screen value using to display button.
Are you suggesting that I set a unique position for all possible screen resolutions?
Your answer
Follow this Question
Related Questions
Detect touch in screen at different resolutions 2 Answers
How to turn on/off multiple lights using GUI buttons? 1 Answer
Dark-Style gui.button 0 Answers
Do screen.width and screen.height get updated depending on screen orientation on Android? 1 Answer
Screen.width/Screen.height not working with multiple resolutions 0 Answers