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
1
Question by omatase · Aug 06, 2014 at 02:40 AM · guitextalign two objects

GUIText position changes with changing resolution

I have a GUIText element that I'm positioning on top of a graphic. The position looks fine at first, but I soon realize it's only staying in the correct place for a single resolution. It's not necessarily a shock that elements shift against the background when the resolution changes, I'm just not sure what the fix for this is. Searches for the problem find a variety of issues that are basically unrelated to the problem I'm having.

I set it up by putting a GUIText element on top of a graphic in the scene and made sure it lines up visually. The coordinates for the GUIText are X: .165 Y: -1.11344 Z: 0. The GUIText is a child of the graphic to which I am aligning it.

Is there an easy way to do like an offset for this GUIText element off of the parent element? The strange thing to me is that I have another image behind the GUIText's parent image and the parent and this other, further back image, stay perfectly aligned with eachother at any resolution.

Appreciate the help.

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
Best Answer

Answer by robertbu · Aug 06, 2014 at 05:01 AM

GUIText lives in Viewport space while the parent object (apparently) lives in world space. It might be possible to make a parent/child relationship work, but I'd approach the problem differently:

  • Break the child relationship so you have two, top-level game objects.

  • Place an empty game object at the position you want to anchor the text relative to the object that was the parent.

  • Make the empty game object a child of the previous parent object.

  • Make sure the anchor and alignment is set correctly so that when the anchor is at the empty child's position, you get the layout you want.

  • Make sure the pixel offset is set to (0,0).

  • Put the following script on the GUIText

  • Select the GUITExt in the Hierarchy view, and drag and drop the empty game you place for position on the 'toFollow' variable.


    pragma strict

    public var toFollow : Transform;

    function Update() { transform.position = Camera.main.WorldToViewportPoint(toFollow.position); }

If your objects move around, you may have to change Update() to LateUpdate() to get smooth movement.

Comment
Add comment · Show 3 · 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 omatase · Aug 07, 2014 at 04:15 PM 0
Share

@robertbu I see, so essentially get an element that will stay aligned with my world-space object and keep the position of my GUIText aligned to that object.

You seem pretty comfortable with the limitations of text in Unity so let me just also quickly inquire. Regarding GUIText vs creating user interface elements with UnityGUI for displaying text, do you have a preference?

avatar image robertbu · Aug 07, 2014 at 04:27 PM 0
Share

Interesting question, but I cannot give you an in-depth answer. I use EZGUI for my UI work, so all elements live in World space. A couple of things come to $$anonymous$$d. It is a bit harder to get GUI elements to follow world positions and to handle changes in resolution. You can rotate GUI elements, but you cannot rotate GUIText. Post it as a new question and someone with more experience in the two can probably give you more points of comparison.

avatar image omatase · Aug 12, 2014 at 12:22 AM 0
Share

@robertbu, appreciate it!

avatar image
0

Answer by UprightToast · Dec 28, 2015 at 02:13 AM

Honestly you guys get so technical??

Any new comers?

Try this video it helped me and it will help you and it is way more easy: https://www.youtube.com/watch?v=_9mOh7_xX2o&feature=iv&src_vid=hzvQnYkS9O4&annotation_id=annotation_3467516253

:D CHEERS

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Changing the font size of GUIText (on Unity iPhone)? 1 Answer

GUI Text line break Alt+Enter doesn't work 1 Answer

How do i make a text box appear on screen after a chest has been opened? 3 Answers

How to parent a GUI text to current game object 3 Answers

In game message displayed on GUI - text and texture 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