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 Sandsnake · Aug 22, 2013 at 12:53 PM · interfacelayouttextfield

Creating buttons or text fields in a relative position irrespective of resolution for an interface control

ISSUE: How do I go about placing GUI or GUILayout buttons, textfields or similar in specific places on my screen regardless of screen resolution.

DETAILS: We are trying to create a user interface that will have a fixed camera (CamA) floating above an object. The object will act as if it is a screen or frame, with 3d boxes at specific positions acting as OnEvent buttons. However, I have a text field that needs to be placed at a specific location on the image overlay so that the text entry field position exactly matches or overlays the filed on the image placed onto the frame.

EXAMPLE: Login in screen, with two text entry fields, name and pwd, which have to be placed exactly over the white space area on the image being used so as to make it seem that the log in text field is actually the image and not the underlying GUILayout field.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Aug 22, 2013 at 02:53 PM

This is a harder problem. The issue is not just making a conversion from world space to GUI space, but that you have issues about how to anchor the objects (GUIs use Rects which are anchored in the upper left corner and world space object generally use a pivot in the center), and height and width issues. The height and width of objects in world space will take different numbers of pixels depending on the screen resolution. The easiest solution is to draw the texture with GUI.DrawTexture(). That way the graphics and the text fields will be in the same space. If you need to have the graphics in world space, then the conversion can be done this way:

 var pointInScreenSpace = Camera.main.WorldToScreenPoint(pointInWorldSpace);
 var pointInGUISpace = Vector3(pointInScreenSpace.x, Screen.height - pointInScreenSpace.y, pointInScreenSpace.z);

You can use empty game objects to anchor the position on the world game object. You can get an approximate size by multiplying the width and height parameters in the Rects used in GUI by the ratio of the screen height you used in authoring to the ratio of the height of the current device.

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 Sandsnake · Aug 22, 2013 at 09:38 PM 0
Share

Thanks for the answer, that makes sense, essentially skinning the object with the image? Would it make more sense then to rather just create a series of 3d objects with OnEvent click listens to act as buttons, frames sliders etc?

Edit: Found a package called NGUI. simplification at its best after the initial learning curve. Still huge thank you to original answerer he gave me a nice way to deal with another issue

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

15 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

Related Questions

How to save panel size in a layout? 1 Answer

Gui Layout Interface 0 Answers

UI Nested Vertical Layout Groups 6 Answers

Trouble creating a horizontal group for Tall and Wide screen orientation! 0 Answers

Is there a list of Shortcut Keys ? 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