- Home /
How to be specific and universal with your onGUI controls?
Perhaps my question is stated in an odd way, but I have been having really strange issues with my GUI buttons - and GUI labels as well.
First off, I may need some general help with the concept of the onGUI function. I have read the scripting reference, so I understand everything there, but I may just be doing it wrong.
When I take the time to position everything where I want it, when I make a stand alone build of my game (I sent it to a few friends for feedback) I noticed on that build the hud is not where it should be. It's slightly off. in the editor, they are placed perfectly!
And the stranger of the two issues is that literally over night my main menu buttons broke. I found out that the numbers I had for their height and width were where i set them, but now they are off screen. So despite me placing them on screen where I wanted them, and without me altering the main menu script or that scene AT ALL, a few days later, the buttons are off screen but with the same height and width I had set. (but not all of them, only half... I'm so confused!)
This is how I have been coding them in (c#):
// Button for Playing the Game
if (GUI.Button(new Rect(startGameWidth, startGameHeight, 125, 35), "", start_GUIStyle))
{
Application.LoadLevel("blipbloop_Game");
s_GameManager.originalBlipPlayerName = tempPlayer1name;
s_GameManager.originalBloopPlayerName = tempPlayer2name;
}
// Button for Controls
if (GUI.Button(new Rect(controlsWidth, controlsHeight, 200, 35), "", controls_GUIStyle))
{
}
The width and height variables specific to each button are just float variables with numbers I assign to them. Should I be coding them differently? ANY help is greatly appreciated! (and I'm aware my controls button doesn't do anything when clicked, and I have images with text as the button states, so that is why the buttons themselves have a blank string in them.)
I usually multiply the screen width for the x location and x size and height for the y location. And y size so that way they will be i'm the proper place no matter what screen size they are placed on
So what would you do specifically? $$anonymous$$y game is running at a fixed resolution, which is why I am confused that the hud elements aren't always in the same spot.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Please help I don't understand what is wrong. 1 Answer
Hiding OnGUI? 1 Answer
[Solved] GUI Error? 1 Answer
Why doesn't my GUI.Label show up? 1 Answer