Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by AngryCSharpNerd · Sep 23, 2012 at 03:24 PM · guiaxiscenteralignmentcentering

GUI centering help

Off centering

I've been trying to get this button and two labels centered. They aren't, as you can see from the image. The GAME OVER image is actually a box, with no GUI skin, that has a screen.width and height, and it is centered at the center point of the image. It's like as if:

<-- | -->

The '|' gui object is actually centered, and it expands out on both sides.

The HIGHSCORE, YOUR SCORE, and PLAY AGAIN are like this:

| -->

It is only centered at the starting point of the GUI objects. You can see that because the PLAY AGAIN box is centered at the left, and expands out to the right instead of the box being centered in the center, and expanding out on both sides. The 'Y', 'H' and the beginning of the GUI button are all aligned at the left together, and I find that very irritating.

I really need help. All three of those, the YOUR SCORE, HIGHSCORE, and PLAY AGAIN have the X-axis position as Screen.width/2-50.

wtf centering.png (224.7 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lockstep · Sep 23, 2012 at 03:47 PM 0
Share

Use a gui skin http://docs.unity3d.com/Documentation/Components/class-GUISkin.html and change the alignment.

avatar image AngryCSharpNerd · Sep 23, 2012 at 03:54 PM 0
Share

I am using a GUI skin. Just not for the GA$$anonymous$$E OVER box, which for some reason has it working. I changed the alignment, but yet nothing changed.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by CgShady · Sep 23, 2012 at 03:57 PM

There are two things to consider : the placement in you OnGUI function, and the GUIStyle you're using.

I usually setup some metrics in the Start function that I later reference throughout the whole OnGUI function.

The following works. But you need to set a GUISkin and change the Label alignment to Middle Center.

 private var location1 : Rect = new Rect(0,0,200,40);
 private var location2 : Rect = new Rect(0,0,200,30);
 private var location3 : Rect = new Rect(0,0,200,20);
 
 var _texture : Texture2D;
 
 var _skin : GUISkin;
 
 function Start () {
     location1.width = _texture.width;
     location1.height = _texture.height;
     location1.x = Screen.width/2-location1.width/2;
     location1.y = 40;
     
     location2.x = Screen.width/2-location2.width/2;
     location2.y = 120;
     
     location3.x = Screen.width/2-location3.width/2;
     location3.y = 240;
 }
 
 function OnGUI () {
     GUI.skin = _skin;
     
     GUI.DrawTexture(location1, _texture);
     GUI.Label(location2, "SCORE");
     if (GUI.Button(location3, "PLAY AGAIN")) {
         // Reload Code
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Text Alignment 2 Answers

Rendering GUI.Buttons in the middle of the screen 5 Answers

Aligning Cards in Hand Deck 1 Answer

Center GUI wondow or box in windowed mode 3 Answers

How Do I Center A GUI Label? 5 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges