Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed May 07, 2018 at 08:09 AM by Myth for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Myth · May 26, 2011 at 12:08 AM · guilabelcenteralignmenttooltip

Text Alignment

is it possible to center align the output of this statement? I keep running into a syntax error of some sort. Any help would be greatly appreciated!

 GUI.Label (Rect (45, 45, 100, 40), GUI.tooltip);
Comment
Add comment
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

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by jahroy · May 26, 2011 at 12:30 AM

Alignment can be controlled using GUIStyles:

  var tooltipStyle : GUIStyle;
 
  function OnGUI ()
  {
    GUI.Label(Rect(0, 0, 100, 100), GUI.tooltip, tooltipStyle);
  }

You can then create a GUIStyle, drag it into the inspector, and change its alignment property.

Comment
Add comment · Show 3 · 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
avatar image Myth · May 26, 2011 at 02:27 AM 0
Share

and how would I create a GUI style?

avatar image Owen-Reynolds · May 26, 2011 at 02:56 AM 1
Share

You don't have to create one -- declaring a GUIStyle (that first line) should set it up in the inspector for you.

avatar image ZestyTaco · May 20, 2012 at 10:01 PM 1
Share

Hello Owen, I added the GUIStyle Variable at the top and edited the alignment in the Inspector tab but when i press play it still shows up in the Upper Left. :(

avatar image
5

Answer by GlennHeckman · May 26, 2011 at 03:12 AM

You can create a GUIStyle by simply declaring a variable at the top of your script which when the script (component) is selected, you can go to the Properties panel and modify the style that way. Unity3d Docs GUIStyle

 var myStyle:GUIStyle;

You can also create a GUISkin and modify the values through the skin as well. Unity3d Docs GUISkin

OR .. you can change the alignment on the individual reference of your label (or button, etc ..) directly through the code below. Be aware though, that once you change the Alignment property, it stays changed for EVERY Other label (or button, etc ..) reference. The way to change just one item would be to follow the code below: (change style, create GUI element, change style back to original state)

     GUI.skin.label.alignment = TextAnchor.MiddleLeft;
     GUI.Label(Rect(10,10,200,400),"My Text");
     GUI.skin.label.alignment = TextAnchor.MiddleCenter;   

Below are the possible Text Alignment options. If you want to change the alignment for a button instead of a label, just change the word "label" for whatever default style it is that you want to change.

     GUI.skin.label.alignment = TextAnchor.MiddleLeft;
     GUI.skin.label.alignment = TextAnchor.MiddleRight;
     GUI.skin.label.alignment = TextAnchor.MiddleCenter;
     GUI.skin.label.alignment = TextAnchor.LowerCenter
     GUI.skin.label.alignment = TextAnchor.LowerLeft
     GUI.skin.label.alignment = TextAnchor.LowerRight
     GUI.skin.label.alignment = TextAnchor.UpperCenter
     GUI.skin.label.alignment = TextAnchor.UpperLeft
     GUI.skin.label.alignment = TextAnchor.UpperRight





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

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Center GUI.Label similar to GUIText? 2 Answers

GUI's documentation lacks of examples 1 Answer

Trouble using C# tooltips 1 Answer

How to make a GUI Label always in the center 1 Answer

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