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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Remo · Aug 17, 2012 at 09:28 AM · guistylealignmentguicontent

GUIContent Alignment inside a Button

I have a menu with a set of buttons. Inside each button I want to add a texture and a string as GUIContent. Both have to be aligned to the left of the button border. I have tried adding style to the GUIContent (texture and string). But this removes the button border. How can I align the texture and string to the left of the button without making the border to disappear?

 var ballTexture : Texture;
 var contentStyle : GUIStyle;
 
 function Start ()
 {
     contentStyle.normal.textColor = Color.blue;
     contentStyle.fontSize = 12;
     contentStyle.alignment = TextAnchor.UpperLeft;
 }
 
 function Update()
 {
     GUI.skin = MenuSkin;  
     GUI.BeginGroup(new Rect(Screen.width/2 - 150, heightVariation, 300, 400));   
     GUI.Box(Rect(0, 0, 300, 400),"");   
     scrollPosition = GUI.BeginScrollView (Rect(0, 0, 300, 400), scrollPosition, Rect (0, 0, 284, 830));            
     var contents : GUIContent = new GUIContent("Ball", ballTexture);                             
     if (GUI.Button(Rect(42, 50, 200, 50), contents, contentStyle))            
     {            
         //do something    
     } 
     GUI.EndScrollView ();   
     GUI.EndGroup ();
 }


 
Comment
Add comment · Show 6
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 Remo · Aug 21, 2012 at 03:17 PM 0
Share

Is is possible to add one more line of text in the GUI.Button.? I have tried

 var ballButtonContent : GUIContent = new GUIContent("  Ball\n Description", ballTexture); 

But "Ball" and "Description" will have the same font styles. I want them to have different font size and color. Please help.

avatar image ScroodgeM · Aug 21, 2012 at 10:01 PM 0
Share

for different font and styles you can draw a button with style1 and label on top of button with style2. using 2 styles in one gui element is impossible. or you can use textures with text that will looks exactly you want to.

avatar image Remo · Aug 22, 2012 at 02:18 AM 0
Share

Thank you Scroodge$$anonymous$$:) But how to add a label on top of a button?? I want a texture in the left, and two texts-in two lines- next to it. Is it possible to add all these in the button? In my example I have a texture of ball in the left end next to it "Ball" is written. I used GUIContent for adding these two in the button. Now I want a description in the next line of "Ball" with a different style. I don't want to use textures for text as of now.Thanks in advance.

avatar image Remo · Aug 24, 2012 at 03:34 AM 0
Share

I have experimented with the label. But that's not what I want. I want the description as the button's content. There is no way to do like that?? Adding two lines of text with different styles?

avatar image ScroodgeM · Aug 25, 2012 at 10:52 PM 0
Share

there's no way to do what you want using built-in controls only. in unity one control = one style. you should search for avoiding solutions to achieve this. for example, use pre-generated textures. i mean render text to texture procedurally with styles you want and draw it on button like a simple texture. or simple use another/custom/self-writed controls/GUI.

P.S. don't ask new questions as comment to another questions, especially it already answered 8)

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by ScroodgeM · Aug 17, 2012 at 09:30 AM

  1. create GUI skin (project - create - GUI skin)

  2. change button style in it

  3. declare GUISkin variable in GUI script

  4. assign created GUI skin to it

  5. in OnGUI method, use it by 'GUI.skin = yourSkin'

Comment
Add comment · Show 5 · 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 Remo · Aug 17, 2012 at 09:58 AM 0
Share

Thank you Scroodge :)...But what styles are to be changed for the left alingnment??

avatar image ScroodgeM · Aug 17, 2012 at 10:08 AM 0
Share

alt text

1.png (35.2 kB)
avatar image Remo · Aug 17, 2012 at 10:20 AM 0
Share

Thank you so much Scroodge$$anonymous$$!!! It worked!! :-)

avatar image ScroodgeM · Aug 17, 2012 at 10:34 AM 0
Share

mark answer as correct to close question though. good luck 8)

avatar image Remo · Aug 21, 2012 at 09:35 AM 0
Share

Already done that..and thanks a lot:)

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

9 People are following this question.

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

Related Questions

How do I get the GUI Icon to stretch? 1 Answer

Customize a scripted GUI 1 Answer

GUI toggle help 2 Answers

GUI.DrawTexture with GUIStyle? 1 Answer

copy a GUIStyle into a new GUIStyle var using JavaScript 2 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