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 Alp-Giray-Savrum · Aug 14, 2013 at 07:11 PM · positionresolutionscalescreenorientation

Locking Object To Screen

Hello, I want to ask question about screen orientation.

I Want to lock my objects to spesific position and scale in any screen resoulution.

For Example:

1024x600 is my testing tablet.

800x640 is another device

I want to make this. In two orientations should be the same. If ı couldn't understand I can send a picture. Thanks.

Comment
Add comment · Show 2
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 robertbu · Aug 15, 2013 at 06:57 AM 0
Share

Are you talking about game objects in world space, or GUI elements? And what is your reference for 'specific position'...the center of the screen or some other position? A picture might be helpful.

avatar image Alp-Giray-Savrum · Aug 15, 2013 at 10:23 AM 0
Share

alt text

all things in this game is "GameObject" not GUI Element. I want their position is fixed at GUI (Or screen I dunno).

untitled.png (29.9 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ________ · Aug 15, 2013 at 10:29 AM

Use the following code on your camera:

 public float worldUnitsPerScreenPixel { get { return (camera.orthographicSize * 2f) / camera.pixelHeight; } }
 public float cameraWidth { get { return worldUnitsPerScreenPixel * camera.pixelWidth; } }
 public float cameraHeight { get { return worldUnitsPerScreenPixel * camera.pixelHeight; } }

You then have the height and width of the camera in the world space, you can make your gui elements children of the camera and offset their local position by half the width and/or half the height to get their transforms aligned with the corners of the "visible area".

Oh FYI, I'm assuming this camera is orthographic.

Edit:

You could also use:

 camera.ScreenToWorldPoint(screenPosition); 

Although I find the first method to be more useful as more data is exposed.

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 Alp-Giray-Savrum · Aug 15, 2013 at 11:21 AM 0
Share

Domo arigato :D I'll try it, If I couldn't handle I'll post there again :)

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

16 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

Related Questions

How to scale everything with screen size? 4 Answers

GUI adapting to screen resolution? 3 Answers

GUI and Screen Resolution 1 Answer

How to maintain high resolution custom background images for GUI elements on different screen sizes? 0 Answers

[Android] Screen Scaling?! 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