- Home /
Screen width and height, how to bypass?!
There's so many questions on this, and not really any useful answers. Using Screen.height seems so bugged, I'm trying to place something in lower left corner, so I put in the y coordinate as screen height minus the height of the button, and it places it somewhat right, now, if I build and change resolution, all of a sudden the button is halfway up the window, and even worse on higher resulotions. How do you work with this?!
Answer by Eric5h5 · Jul 25, 2012 at 04:12 AM
There's nothing bugged about it. You don't need to bypass it, you just need to use it correctly. I assume you're doing something like storing the screen height instead of using it dynamically.
function OnGUI () {
GUI.Label (Rect(0, Screen.height-20, 100, 20), "Works fine");
}
Tell me, if I use a setup where I have the variable of the window rect like
var window = Rect (Screen.height-300,25, 350, 300);
and then calls it from on gui like
Window = GUI.Window (11, Window, WindowSettings, " ");
This does not update the placement, this sets it as it is in when I put the script on, then stays in that position even when I change resolution on startup?
You can't use Screen.height for the x value. (Well, you can, but it's totally wrong.)
Your example doesn't update the placement because I'm assu$$anonymous$$g you only set that variable once (perhaps on start?) If you set that variable on Update it should change when you change the resolution.
But Eric is right, you've got the x-coordinate set as relative to Height, so it's probably not going to give you expected results
X as relative height? I don't think so? I've got 0,height, I'm assu$$anonymous$$g x,y, so that means i've got height as y, not x. Anyway, what Perchick said might make sense, that it's fixed, and not in the update. But how do I update it, when I've made it like I have.
var HUD_LoginWindow = Rect (25,25,260,140);
function OnGUI () { HUD_LoginWindow = GUI.Window (1, HUD_LoginWindow, HUD_LoginSettings, ""); }
function HUD_LoginSettings() { }