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 alone1992 · Nov 28, 2013 at 01:42 PM · guipositionworldtoscreenpoint

How to set my text to real object

Hello I want to set my text in GUI layer to a position of an object but can't do that work with some thing like this code because my screen size maybe change and this code hang when screen size is change but my X variable is always in true place and my main problem is Y

 var TextStyle = new GUIStyle();
         TextStyle.font = font;
         TextStyle.normal.textColor = Color.white;
         var position = Camera.main.WorldToScreenPoint(timer.transform.position);
         
         GUI.Label(new Rect( position.x,Screen.currentResolution.height - position.y - 450, 100, 20), "123" , TextStyle);

I want to put my text in this place :

alt text

thanks

capture.jpg (26.5 kB)
Comment
Add comment · Show 1
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 alone1992 · Nov 28, 2013 at 08:06 PM 0
Share

Because I don't know how to change 3d text with script and I can't set that 3d Text GUI with best quality.

If you show me the true way I'll use that.

From other side my game is 2d not 3d!!

2 Replies

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

Answer by Tomer-Barkan · Nov 28, 2013 at 01:46 PM

If you want it in a constant world position and not screen position, why not use 3d text instead of GUI text?

Edit:

Don't worry about your game being 2d. I always use 3d text for 2d games, as long as it's facing the camera it will appear 2d for you, and if your game is 2d then I don't expect the camera to rotate around it...

1 - Create a 3d text object, select the font and color from the inspector (or code if you prefer).

2 - Set the scale of the 3d text object to 0.1,0.1,0.1 so that it appears more crisp.

3 - Change the font size parameter of the object if you want to make the writing bigger. It will remain sharp.

4 - To change the text from code, create a reference to it in your script as TextMesh (set the reference in the inspector), then set the text property to whatever you want it to display. See example below.

5 - If you don't want to set the TextMesh in the inspector, you can use GameObject.Find() to find the object by name, and then use GetComponent to get the TextMesh component of the object.

 var textMesh : TextMesh;
 
 function Start() {
     textMesh.text = "123";
 }

   


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
avatar image
1

Answer by karljj1 · Nov 28, 2013 at 01:57 PM

Try this:

http://www.41post.com/3816/programming/unity-scaling-the-gui-based-on-the-screen-resolution

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 alone1992 · Nov 28, 2013 at 08:07 PM 0
Share

thanks dear, my problem is position not scale and I can't control my Y axis position.

avatar image karljj1 · Nov 28, 2013 at 08:57 PM 1
Share

Well your taking 450 regardless of the actual screen height. You want to normalise the value. For example if the value 450 works when the screen height is 1080 then do this

 float val = ( 450f / 1080f ) * Screen.height;
 GUI.Label(new Rect( position.x,Screen.currentResolution.height - position.y - val , 100, 20), "123" , TextStyle);
avatar image alone1992 · Nov 29, 2013 at 06:52 AM 0
Share

It's good idea.

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

GUI Button Transform Screenspace 0 Answers

WorldToScreenPoint returns the same value when facing the opposite direction. 0 Answers

v4.6 UI Element's Positioning Incorrect 1 Answer

Change sorting layer of UI without changing position in hierarchy 0 Answers

Positioning a GUI Text? 2 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