Draw GUI.Button on certain position on a scrollable background
Problem is in a 2D game I have a large background around 2 screens wide. And on there I got 4 buttons placed on top of background all over complete width. Now when I swipe of move my mouse around I scripted that the camera will move with it. So for the GUI.Buttons (Unity4.5) to stick on their place I used a variable drawX drawX = Camera.main.transform.position.x * 100; The 100 is for calculating it to pixels. I then add this to my buttons when drawing. scaleX = Screen.width / 1920f; scaleY = Screen.height / 1200f; if (GUI.Button(new Rect((500 - drawX) * scaleX, 700 * scaleY, 325 * scaleX, 425 * scaleY), "")) Now the problem is that under 1920x1200 my target resolution everything works exactly pixel perfect. But when changing the resolution or aspect ratio to something else the drawX increases to much or not enough so the buttons don't move on the same pace as they did in the 1920x1200 version. Somebody got the solution for me?
I’d wager it’s related to you using this “DrawX” value for only one of the rect coordinates. I don’t know Unity, but I’d wager that it at least needs to be applied to one other corner of the rect (the other X).
- Database Administration Tutorials
- Programming Tutorials & IT News
- Linux & DevOps World
- Entertainment & General News
- Games & eSport