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 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.

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

I make a camera that change position every X seconds but i need different waiting time for each position that take. 0 Answers

Set game object position relative to the Camera 1 Answer

How to access a Text Mesh Pro Font Asset's glyp info from c#? 1 Answer

Need help on the 3ds max style camera control 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