- Home /
X and Y positioning(buttons). How do they work and why does building the game change their positions?
Hi I made a quick game where the buttons are on the left hand side. I am trying to allign them with x and y positioning. The game is 800x600 and below is my co ordinates for the buttons:
if (GUI.Button(new Rect(Screen.width/2+300, Screen.height/2-120, 80, 50), "Open Store!")){
GameObject.Find("maincontrol").GetComponent<inventory>().cash();
}
}
if (GUI.Button(new Rect(Screen.width/2+300, Screen.height/2-60, 80, 50), "Display")){
GameObject.Find("maincontrol").GetComponent<fadeout>().fade();
camera1.enabled = true;
camera2.enabled = false;
camera3.enabled = false;
}
if (GUI.Button(new Rect(Screen.width/2+300, Screen.height/2, 80, 50), "Town")){
GameObject.Find("maincontrol").GetComponent<fadeout>().fade();
text1=false;
camera1.enabled = false;
camera2.enabled = true;
camera3.enabled = false;
instore=false;
intown=true;
intopfloor=false;
}
if (GUI.Button(new Rect(Screen.width/2+300, Screen.height/2+60, 80, 50), "1st Floor")){
text1=false;
camera1.enabled = false;
camera2.enabled = false;
camera3.enabled = true;
instore=false;
intown=false;
intopfloor=true;
}
}
please take note of only the rect positions. My goal is ideally having them on the right hand side alligned with the background. Here is my ideal position and one through trial and error I have obtained: This is from the built version of the game.
![IMG]http://i1159.photobucket.com/albums/p628/xLiemx/Capture2_zpsd41ee840.png[/IMG][1]
Now this is where the problem lies. In unity testing, the position of the buttons do not reflect the actual outcome when I built the game. In unity testing, the below image is where I had to place the buttons to get the desirable affect above.
![IMG]http://i1159.photobucket.com/albums/p628/xLiemx/capture1_zps9648ea86.png[/IMG][2]
Obviously I seem to not understand the new Rect(Screen.width/2+300, Screen.height/2-60, 80, 50)
and would like help in..
details on proper uses
what my actual numbers should be. (please note this is a 800x600 game)
Any help is greatly appreciated. Essentially I'd like to understand so in future, when I use the position code on a 2d surface for buttons, the placement I do in unity testing will be the actual position for when I have built my game on a 800x600 scale.
[1]: http://i1159.photobucket.com/albums/p628/xLiemx/Capture2_zpsd41ee840.png
[2]: http://i1159.photobucket.com/albums/p628/xLiemx/capture1_zps9648ea86.png