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 el-santia93 · Sep 04, 2013 at 09:00 AM · gui-text

How do i fit a Guitext to a particular position for all screen resolutions?

my current gui text is at the position (0.9,0.97,0) for standalone screen res,however when i change screen res the gui text appears in a wrong place. Please help

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 $$anonymous$$ · Sep 04, 2013 at 10:18 AM 2
Share

use Screen.width and Screen.height on the rect for the first two values.

Eg: (Screen.width / 2 -25, Screen.height /2 - 25, 50, 50)

This way it takes the current screen width divide for two and then $$anonymous$$us 25 which is half the element size, same on the height. This will perfectly center your element on all resolutions.

So you have to play around with that and always consider the element size you input.

EDIT. Oh sorry, you mean to position the game object in the scne, not a gui function rect, well you can still use the above variables to calculate your Vector3. One thing, Screen.width and height are integers, so you need to cast them for the Vecto3, probably is best to do it once on Start or Awake.

avatar image el-santia93 · Sep 04, 2013 at 10:59 AM 0
Share

i dont really understand could you please show me an example? thanks

avatar image Eric5h5 · Sep 04, 2013 at 09:39 PM 0
Share

@$$anonymous$$: GUIText objects use viewport space, not screen space, so that won't work.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by aldonaletto · Sep 04, 2013 at 12:13 PM

The position of a GUIText is relative to the screen, no matter which are its dimensions: (0,0) is bottom left, (1,1) is top right, and so on. Unfortunately, in many cases this isn't sufficient to keep the text at the position you want. If the text is some kind of display info like health, status, points etc. you may get good results by setting the GUIText Anchor field properly: if the text is supposed to stay at the top-right corner (seems to be your case), select upper right anchor - this will make the text align its upper right corner to the viewport position.

But if your text is supposed to align to some scene object, it's better to use a script like ObjectLabel, a creation of our diligent colleague @Eric5h5 that makes the label follow the target object. Finally, if you want the text to keep its position and also scale according to the screen, use GUI.Label instead of GUIText and adjust the GUI matrix, as shown in this question.

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

18 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

Related Questions

Inheritance (Printing a toString for subclasses) 3 Answers

guitext count up when collide 1 Answer

Attach GUI element to newly spawned player as their GUI 2 Answers

GUI text Messages does not show and points counter do not stop at its prefixed limit 2 Answers

GUI.Toolbar ? 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