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?

  • 2
    \$\begingroup\$ Why not just going for the new Unity Gui? It handles many things by itself, and it's much easier to use. OnGui/Gui should be used just for testing purposes \$\endgroup\$
    – user100681
    Commented Nov 26, 2017 at 18:34

1 Answer 1


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).

  • \$\begingroup\$ Well the Rectangle needs (x,y,width,height) so it doesn't necessarily has an other corner. \$\endgroup\$
    – MrME
    Commented Jan 16, 2015 at 16:29
  • 2
    \$\begingroup\$ Are you sure you don't want to use the new Unity UI? \$\endgroup\$
    – SanSolo
    Commented Oct 14, 2015 at 3:35
  • 1
    \$\begingroup\$ yup the new UI is really simple and handles many things for you :) \$\endgroup\$ Commented Nov 13, 2015 at 8:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .