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 /
  • Help Room /
avatar image
0
Question by SyedaAfreen · Nov 17, 2016 at 04:51 AM · labels

what can I use to write a text inside a box?

Hi,

I am trying to write a text inside a box.I have tried it using square of sprites but square and text are not merging they are creating a huge distance between them.what else can I use? So, that I can fit text inside a box which might give the look of labels.Please help me out.

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

· Add your reply
  • Sort: 
avatar image
0

Answer by Dibbie · Nov 17, 2016 at 06:42 AM

You can use the UI system for "labels".

Either a Panel or a Image, you can then parent that to a Text UI element.

When you do that (putting the Text game object, as a child to your Panel or Image gameObject, all while inside the Canvas parent), you will be restricted to sizing the ratio of the text's bounds, to the parents bounds -- so in this case the Panel or Image.

There is a handy tool on the top left of the RectTransform you can use to make sure the scale/ratio is right and automatically adjusts to the parent. Click that small box and several others will appear -- the bottom right box, holding down SHIFT first and click it, then ALT and clicking it again, will center it to the parent, then size it to fix the parent perfectly.

After this, on your Text game object, you can check "Best Fit" if youd like to make sure you can continue typing and have the size of the text automatically size down or up depending on how much text overlaps, or underlaps the parent. Theres a lot of weird things with working around this, youll have to tweak for what you want though.

And without any scripting what-so-ever, you just created a "label". (iv included some visuals to help illustrate my "steps").

For ease of your life later, if you plan to have these "labels" pop up at run time, you can create a prefab of them, though if they are only ever going to be on that canvas, you can just duplicate that one label you already made. The even nicer thing about the Canvas system, is that you can mount it any camera in your scene, or even freely in Unity space, so you can align individual Canvas's to objects in your scene rather then being "restricted" to only being about to align them to cameras.

Step 1

Step 2

Step 3

Step 4

Step 5 (with end result)

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

Answer by SyedaAfreen · Nov 17, 2016 at 10:59 AM

Hi @Dibbie,

By following your steps I got panel and text.But when I am running my application the panel is somewhere and text is at some other position.How to fix them together and when I want to attach text within box whose position should I give text position or panel position? Please help me

Comment
Add comment · Show 1 · 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 Dibbie · Nov 17, 2016 at 05:29 PM 0
Share

Steps 3 and 4 kind of go over that -- make sure its all parented properly, then your text component will take the parents (panel in your case) Transform, so 0 0 0, becomes the center of the parent, rather then the center of the world.

When parenting the Text, if the scale changes to very large or small numbers from default 1 1 1, thats fine, leave them - its again, inheriting the parents scale accordingly.

After you parent the text, if it is off, just simply manually fix both, and they shouldnt change at run time.

By code, you shouldnt ever be moving the text at all, if you want to move the label around, by code or manually, you should ONLY move the parent (panel), because the text is linked to the parent, it will follow accordingly, same thing for rotating and scaling.

Hope that helps.

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

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

Related Questions

Click on different objects to move the camera 2 Answers

jumpy dinamic font 0 Answers

OnGUI() problems in unity 5.6, worked with Unity 4. 0 Answers

Label doesn't affect GUI 0 Answers

Label and line renderer not showing 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