- Home /
GUI button in middle of screen
Hi guys i made a GUI button and i would like to center it in width here is the code i use:
var customGuiStyle : GUIStyle;
public var quitRect : Rect;
customGuiStyle.alignment = TextAnchor.MiddleCenter;
function OnGUI()
{
if(GUI.Button(quitRect,"Quit", customGuiStyle))
{
Application.Quit();
}
}
Answer by DracoScorpius · Apr 04, 2012 at 06:38 PM
You may have to change its position in the inspector. With my GUI textures, I have them set to 0.5 on the X and Y axis,but you may have to play around with the positions yourself. Also, ensure your textures are not children of another object, since that may mess things up as well. Once it's in place, however, you can probably make an empty parent to add all you GUIs to.
Hope this helps :)
Answer by Deozaan · Apr 05, 2012 at 06:22 AM
I noticed a question with almost the exact same title. Perhaps you can find an answer if you search for one. Here's what I found:
http://answers.unity3d.com/questions/235212/gui-button-in-the-middle-of-screen.html