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 /
avatar image
0
Question by Lambastard · Apr 01, 2018 at 04:26 PM · user interface

Self-resizing text and background

I'm a bit confused by all the various components and the new (to me) Unity UI in general.


Let's say I want to have self-resizing text elements with a background image fitting the size of the text.

My first approach was to just have a single GameObject and add text and/or image components as necessary. Well, that's not allowed - text and image cannot be on the same GameObject, it seems.


So I went on to write some code that generated several GameObjects in a hierarchy. And because not all elements will have a background image, and not all will have text, I'd like to generalize it all of it as in the following UI element hierarchy:

 Element
     Background Image
     Text

Now, I figured out this doesn't work because the Text actually needs to be a child of the background image in order for transparency and so on to work out. So it's actually

 Element
     Background Image
         Text

Shame about that. But here come my as of yet unresolved troubles - where do I put all the various Unity UI components?


Obviously the text component goes into the text GameObject and the image component goes onto the Background Image GameObject.

But where do I put ContentSizeFitters? LayoutElements?

Which pivots and anchors do I set to what? Where do I change preferredSizes and rect sizes and in what ways?

What do I need to do when the text changes? When I need to reposition an element? When the screen size changes?

Also, I'd like to be able to automate it all through code, so if you can please explain it as if the editor didn't exist.


Sorry about the vagueness of the question; I'm still wrapping my head around all this UI system.

Comment
Add comment · Show 1
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 Glurth · Apr 01, 2018 at 07:24 PM 0
Share

Before going into an answer, I'd like to suggest you try out a "Canvas". Children of a Canvas use RectTransforms, rather than regular transforms, which include stuff like anchors. Canvases also have the optionaly-ability to automatically resize their contents based on screen size. I'd also suggest you add some built-in components, like an InputField to the canvas, and see how unity organizes the various gameobjects, and components that make up the control.

0 Replies

· Add your reply
  • Sort: 

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

76 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

Related Questions

UI System for Non-minimal User Interfaces 0 Answers

Simple UI not appearing once deployed to iOS (4.6.2) 1 Answer

3D Unity-Terrain realtime modifier 2 Answers

[UI] Profiler scroll rect 0 Answers

2d view of my panels/UI doesn't show correctly in Scene view 1 Answer


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