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 Angelf228 · Nov 05, 2014 at 07:34 AM · guitextscreentimerlabel

How to set text(timer) to a fixed place

Hey there :) I am working on a project where I include a timer, but it seems that it won't stay at the same place, dependin on the game's resolution. I would like to stay on a specific place on the screen, how is it possible? Thanks for you advices.

Here is the timer's script, along with how I determine its position:

 var startTimer: int;
 var minutes : int;
 var seconds : int;
 var style : GUIStyle;
 
 function Start() {
     startTimer = Time.time;
 }
  
 function Update() {
     var time = Time.time - startTimer;
     minutes = time / 60;
     seconds = time % 60;
 }
  
 function OnGUI() {
     GUI.Label (Rect (850, 800, 200, 20), String.Format ("{0:0}:{1:00}", minutes, seconds), style);
 }

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

Answer by devluz · Nov 05, 2014 at 10:52 AM

You will need to calculate the position relative to the resolution. Screen.width and Screen.height gives you the size of your screen. eg if you want to place it at the centre top side of the screen you could try Screen.Width / 2. If you want it on the bottom right corner try to put the start point 200 pixels from the right side:

e.g.

 function OnGUI()
 {
      GUI.Label (Rect (Screen.width - 200, Screen.height - 20, 200, 20), String.Format ("{0:0}:{1:00}", minutes, seconds), style);
 }

(example is untested. I am on a computer without unity right now)

Play a bit around with the values in Rect. I am sure you will find a good position.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to clear a GUI Label 1 Answer

Can't draw GUI.Label text on subpixel values 0 Answers

GUI label/text appear/disappear 1 Answer

OnGUI called after LateUpdate screwing up debug text database 1 Answer

GUI & GUI Text Disappear When Publishing 6 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