• 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
Question by hema · Jan 21, 2014 at 10:24 AM · guitextguilayoutguibox

Change gui box height based on text content?

Hi All,

I have variable length text files. My requirement is the GUI box length/height should change based on the text content such that the text content should fit within the box. And also the text content in the box should get aligned. Suggest any ideas.

Thanks in advance.

Comment
luislodosm

People who like this

1 Show 0
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

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by ArkaneX · Jan 21, 2014 at 05:30 PM

If the width of the box is known, then you can use GUIStyle.CalcHeight. If you want to calculate width as well, then you have to use GUIStyle.CalcMinMaxWidth first. Please note that the second method will return different width values only if your style has word wrapping enabled. Text alignment can be set in your GUI style in the inspector, or programmatically by GUIStyle.alignment.

Word of warning: avoid modifying default style, like

 GUI.skin.box.alignment = TextAnchor.MiddleCenter;

because this is not reversible (or at least not straightforward). If you want to play with style properties, just create a new style and configure it in the inspector. Or alternatively, create new one in code using default style as constructor parameter:

 var myStyle = new GUIStyle(GUI.skin.box);

Comment

People who like this

0 Show 2 · 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 hema · Jan 24, 2014 at 06:03 AM 0
Share

Thanks for your reply. The above mentioned text files are Questions.

So can you suggest me a way to provide answers.The answers are of two types,one is of four options to choose one correct answer and the other is of match the following type(the user should match the images with the text).

avatar image ArkaneX · Jan 24, 2014 at 09:32 AM 0
Share

In first case I would probably set the answers width to a fixed value, depending on screen width, and for each answer calculate the height using CalcHeight method. And then, position the answers vertically according to calculated heights.

As another option, if your answers are short, you can display them in two rows and two columns format (like in Who Wants to Be a Millionaire)

And regarding the image/text matchig, I think you can use the same formats. Depending on the size of the image, it might be a good idea to display it on the left, while possible matches on the right.

But ultimately it's up to you - just try a few options, ask your friends and see which layout they like.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

19 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Create GUI Texture using GUI Layout 2 Answers

Text position of a game object moved upon a key input and overlaid on the other image. 0 Answers

GUILayout.BeginScrollView in GUI.Box won't Scroll 1 Answer

Inserting text into GUILayout Box? 3 Answers

ArgumentException: control 1s position in group with only 1 control 0 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