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 itkeepshappening · Mar 27, 2014 at 09:49 PM · programmingscoringgui text

How do I change the position of GUI text?

Hello, I'm a new to programming and I was wondering how I should modify my script to put my GUI text at top center of my screen. This is my script.public class HUDscript : MonoBehaviour {

 float playerScore = 0;

 // Use this for initialization
 void Update () {
 
     playerScore += Time.deltaTime;
 }
 
 void OnGUI () 
 {
 
     GUI.Label (new Rect (10, 10, 100, 30), "score: " + (int)(playerScore * 1));
 }

}

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

Answer by Gruffy · Mar 27, 2014 at 10:04 PM

If you replace you entire GUI.Label line with the one below you should see this turn up in the middle and at the top.

  GUI.Label (new Rect (Screen.width - (Screen.width * 0.5f)-50.0f, Screen.height - Screen.height, 100.0f, 30.0f), "score: " + (int)(playerScore * 1));

Now, if you look at the code, all that has been done is a call to the globally available screen parameters natively populated by Unity based on your screen size settings or the default ones if left alone.

what it is saying is... the new rectangle x position should be half of the screen width

screen.width (the full width of screen)

minus

half of the screen width (Screen.width * 0.5f )(effectively divide by 2 but technically faster)

the

50.0f is half of the width of your gui label, which was 100.0f

next we have the height and we are doing the same but without reducing the height by half before minus-ing that from itself.

Anyway, its a start, hope that helps. take care bud Gruffy

Comment
Add comment · Show 2 · 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 itkeepshappening · Mar 28, 2014 at 12:25 AM 0
Share

Thanks alot :)

avatar image Gruffy · Mar 28, 2014 at 10:57 AM 0
Share

No worries dude, please ,mark it as an answer though, so that other may find this resolve when/if they too come across the same issues. Thanks and take care. Gruffy

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

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

Related Questions

Multiple Cars not working 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Trouble with OnCollisionEnter and Exit 1 Answer

Guidance to read write and learn Programming 3 Answers

On Button Press, Show GUI Window 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