- Home /
GUI always changes Position with different resolutions.
Hello im not to sure if this has been answered before i have looked trust me from watching youtube tutorials to searching forms even look for assets store for help.
the problem is that when the player dies i need a death screen to appear it works in full screen mode but nothing else not even in the test build. i write in c# and a lot of answers are in unityscript / javascript
heres what i got
{
if (dead == true){
GUI.Box (new Rect (860,200,300,500), "Level Failed");{
// restart button
if(GUI.Button(new Rect(930,270,100,20), "Restart Level")) {
reboot();
}
//exit button
{if(GUI.Button(new Rect(930,370,100,20), "Quit Game")) {
Application.Quit();
}
}
}
}
}
i know it poorly formatted but i want to get it working at least then clean it up later. Any help would be much appreciated
Answer by AndyMartin458 · Feb 26, 2014 at 12:36 AM
You should be doing your rectangle coordinate calculations based on Screen.width and Screen.height. You should also do this for your other types of GUI objects, but I showed you the box as an example.
//Try doing these calcualtions of the width and height to fit your box within the screen
GUI.Box (new Rect (0, Screen.width / 5f, 0, Screen.height / 5f), "Level Failed");
how would i go about finding the width and height ,when i tried the code the box wasn't on the screen at all. or is it that i need to set the size of the box?
Try something like, GUI.Button(new Rect(Screen.width/5f,Screen.height/5f,100,20)
ok so i have the box not moving no matter the size i tried to to this with the buttons but no successes the still move around here is the box code
GUI.Box(new Rect(Screen.width/2.4f,Screen.height/3.3f,500,200), "Level Failed");{
and the button code
if( GUI.Button(new Rect(Screen.width/2f,Screen.height/2.9f,200,20), "restart level")) {
any ideas why this is happening?
@kiwiboys the buttons should behave the exact same way. The one thing that might not be working is the hardcoding of the width and height of the button. If you want to it to start at 1/2.4 of the screen width, try making the total width something like Screen.Width/ 5 ins$$anonymous$$d of 500.
hmm i will give this a go. but because this game is intended to run on multiple platforms and resolutions i may need to look into other ways of achieve it
Answer by zharik86 · Feb 26, 2014 at 07:13 AM
would NGUI work its at the assets store? Because I need to change it to a picture later and I don't think matrixs work with that texture.
@kiwiboys I, unfortunately, didn't work with NGUI. Generally I work with GUI from Unity. But it is sure that for NGUI scaling for different resolution of screen shall be provided.
Your answer
Follow this Question
Related Questions
get the mouse cursor position x and y and make gui follow on trigger -1 Answers
c# - void method from external class. 2 Answers
Efficient GUI resizing 0 Answers
Styling an individual button in SelectionGrid 0 Answers
Neutral state for toggle buttons? 2 Answers