- Home /
Question by
NutellaDaddy · Mar 15, 2014 at 04:33 PM ·
guimiddlenew rect
How can I make a GUI Rect be in the direct middle of the screen?
Screen.width/2 doesn't seem to be working. ANybody know how to do this?
Comment
Best Answer
Answer by saruul34 · Mar 15, 2014 at 05:00 PM
public float h = 0;
public float w = 0;
// Use this for initialization
void Start () {
if(h == 0) h = 20;
if(w == 0) w = 20;
}
// Update is called once per frame
void OnGUI () {
if(GUI.Button (new Rect(Screen.width / 2 - w/2, Screen.height / 2 - h/2, w, h), "X"))
{
print("Hey hey");
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613140320im_/https://answers.unity.com/themes/thub/images/avi.jpg)