- Home /
Why does my GUI layout get messed up in player
When I publish to the stand alone player all of my GUI elements and texture GUI buttons are all out of whack.... Why? How can I fix this? What I see in the game editor is not what I get when published.
GUITextures? Use transform to position ins$$anonymous$$d of pixel offsets.
Just a suggestion, but have a look at the new UI features in 4.6. A significant amount of the positioning and sizing for multiple resolutions is taken care of for you.
Of course switching to the new UI might not be feasible if you've got a large investment in the old methods. It was a difficult decision here... :-) I think it paid off, though.
Actually, switching to the new system is not a big issue even if you have a large amount of old GUI. This is due to the fact that most is manual and visual so only the actions for the events remain in the end. I would also recommend the move to the uGUI.
Answer by fafase · Nov 27, 2014 at 05:38 AM
What you see in the editor is probably based on the current size of it. GUITexture and other GUI component requires a hardcoding system most of the time.
If you place them at 0.5, 0.5 then it will be in the middle all the time, but I have noticed that if you parent the object, then it does not work.
What I do is to make them child so that it is clean in the hierarchy, and then modified the pixelInset by code.
void Start(){
float size = Screen.width /20f;
Rect r = new Rect(Screen.width - size, 0, size, size);
guiTexture.pixelInset = r;
}
I think this will go top right corner but you get the idea that it will get always in the same spot.
Thanks fafuse, that was very helpful. Also I'm trying to make my final out put for touch screen LCD car monitor that has a resolution of 800 X 480 and I notice that the player does not have that option so I'm thinking that also might be part of my problem, will the method you described above fix this issue too?
Oh one more thing, is this java because I pated it in just to try it out and it gave me errors saying that I needed to : Assets/Scripts/HomeScreenLoaderButton.js(3,10): UCE0001: ';' expected. Insert a semicolon at the end.
and
Assets/Scripts/HomeScreenLoaderButton.js(2,11): UCE0001: ';' expected. Insert a semicolon at the end.
First you can set the resolution of your screen to whatever you want in the editor. In the game view, you have the list of resolution and if you click the plus, you can make your own.
The code is C# but the same goes for UnityScript:
void Start(){
var size : float = Screen.width /20f;
var r : Rect = Rect(Screen.width - size, 0, size, size);
guiTexture.pixelInset = r;
}
Thanks again, :) It's been a little while since I had played around with Unity and I forgot all about the editor view option, this gives me a much better idea of how things will look. I keep doing test builds to see if it all fits right on screen lol I pasted that code into the top of my buttons script and I still get those same errors??
Somewhat related is another issue I'm having trying to get a GUI texture background to stay behind my other texture GUI elements. Even an animated GUI texture to stay overtop of everything so as when the animation is finished then everything on the screen becomes visible. Can't seem to figure out how to make that work although I'm sure it can be done as I have seen it.
Your answer
Follow this Question
Related Questions
Screen.width/Screen.height not working with multiple resolutions 0 Answers
How to apply multiple styles to the same line(s) of GUI text 1 Answer
How to set GUIStyle.font 0 Answers
multiple apks to match certain devices 0 Answers
How to change the color of a GuiLayout.button thats part of the editor 0 Answers