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 /
avatar image
0
Question by filler03 · Mar 14, 2014 at 09:48 PM · uiaspect ratioplatform-support

How to position and scale an element based on the aspect ratio?

I have UI elements positioned in the correct places on a 16:9 aspect ratio. I would like to make these elements automatically reposition and scale on start to match the aspect ratio, being that I will need them to work on multiple platforms.

Edit: The elements are simply GameObjects. As far as anchor points, they do not touch the sides of the screen necessarily but I would like them anchored to one of the sides, depending on the placement of the element.

Comment
Add comment · Show 3
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 Howie Stambler · Mar 14, 2014 at 09:54 PM 0
Share

I am having the same problem.

avatar image robertbu · Mar 14, 2014 at 09:57 PM 0
Share

You may need to be more specific to get your answer(s). The solution will depend on the kind of object(world object, GUITExture/GuiText, GUI.* class calls), and how you want to define your anchor points. This issue has been covered a number of times on UA, but usually the answer is specific to the OP situation.

avatar image robertbu · Mar 14, 2014 at 10:13 PM 0
Share

Orthographic or Perspective camera? I assume all the elements will be the same distance from the camera?

1 Reply

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

Answer by robertbu · Mar 14, 2014 at 10:38 PM

For a world object, the easiest solution is to make all your visible object a child of an empty game object. The empty game object is placed at the anchor point, and all anchor points will be places on some edge(s) of the screen. If you want the visible object to stand off the edge by a bit, you can just place the anchor a bit outside the object.

To place the object, you can use Viewport coordinates. Viewport coordinates go from (0,0) in the lower left corner to (1,1) in the upper right. So if you had an object with an anchor point in the lower right that you wanted to anchor to the lower left corner of the screen you could this with a script on the anchor object:

 function Start() {
     transform.position = Camera.main.ViewportToWorldPoint(Vector3(1.0,0,dist));
 }

For a perspective camera, 'dist' will be the distance on the local 'z' axis the objects is away from the camera. For exmaple if your camera was at -10 on the 'z' axis, and the object to be position as at 1 on the 'z' axis, dist would be 11. For an Orthographic camera, you can ignore 'dist' or just overwrite the 'z' parameter that comes out of the ViewportToWorldPoint() call.

If you wanted to anchor to the bottom middle, you would place the anchor object in the bottom middle of your visible object and use (0.5,0,dist) in the ViewportToWorldPoint(). And so on.

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

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

21 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

Related Questions

Keep aspect ratio of the SVG Image in Canvas 1 Answer

Aspect ratio affects ScrollRect? 0 Answers

UI Position Correction for worldspace UI? 1 Answer

UI different between 16:10 and 3:2 (portrait) how can i fix? 3 Answers

Preserving aspect ratio for layout group elements 3 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