• 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 prsolucoes · Aug 27, 2014 at 05:40 PM · camerapositionfonttextmeshalign

Align TextMesh on Top Right

Hi,

I want know (i search a lot and tried a lot of codes) how i can align a TextMesh (or my extension that im using for it EasyFontTextMesh) on Top Right position of screen.

Like this: https://dl.dropboxusercontent.com/u/7386482/top-right.png

Im using ortographic camera for a 2D game. Im porting my game with cocos2d-x (https://itunes.apple.com/br/app/flyforcoins/id870686218?mt=8) to use Unity3D. Im near to finish, this is a problem that i cant solve on this week :(

Thanks for any 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

1 Reply

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

Answer by robertbu · Aug 27, 2014 at 05:53 PM

Set the anchor for the text to upper right. Then execute this code:

 #pragma strict
 
 function Start() {
     transform.position = Camera.main.ViewportToWorldPoint(Vector3(1,1,10));
 }

Consider using GUIText. You can set the anchor to upper right and the position to 1,1, and no code is involved unless you need to change font size.

Comment
Add comment · Show 5 · 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 Owen-Reynolds · Aug 27, 2014 at 06:14 PM 0
Share

To reiterate: the ANCHOR option.

As far as I can tell, the Alignment dropdown does nothing.

Also, just for fun, exact placement with Anchor depends on the font. I have one commercial font where middle acts like upper and lower acts like middle (and upper is "add an entire blank line on top."

avatar image robertbu · Aug 27, 2014 at 06:42 PM 0
Share

@OwenReynolds - would he be better off using Renderer.bounds to position the text rather than setting the anchor and position? Renderer.bounds for Text$$anonymous$$esh is not precise, but it would suffer from the problems you outline.

avatar image prsolucoes · Aug 27, 2014 at 06:52 PM 0
Share

Hi Robertbu,

Your answer is near to be correct, the problem is when i use your code, the score text is out of screen:

SS: https://www.dropbox.com/s/tnq8w9qp1mosmqg/Screenshot%202014-08-27%2015.46.23.png?dl=0

It can be 20px distant from border top and right too?

 private void UpdateScoreText()
     {
         scoreText.Text = GlobalObjects.score.ToString();
         scoreText.transform.position = Camera.main.ViewportToWorldPoint(new Vector3(1,1,10));
     }
avatar image robertbu · Aug 27, 2014 at 10:37 PM 0
Share

@prsolucoes - did you set the Anchor to Upper Right?

avatar image prsolucoes · Aug 28, 2014 at 06:04 AM 0
Share

Hi, i solve the problem with:

scoreText.transform.position = Camera.main.ViewportToWorldPoint(new Vector3(0.99f,0.94f,10));

Thanks robertbu.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Screen to world point - parented camera 0 Answers

How to get the screen Position of a particular character/letter in TextmeshproUGUI ? 1 Answer

How can I get exact screen position of 3D game object in front of camera while using cardboard in VR game? 1 Answer

Camera Rendering Skewed Until Transform Adjusted 0 Answers

Crosshair Not Parallel To camera 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