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 wahoosjw · Feb 12, 2013 at 01:14 AM · timenoobtime.time

Digital Clock: Time.time > 60

I am trying to make a functioning digital clock and it works except for the fact that I cannot seem to get the minutes to reset after 60.

 var textObject: GUIText;
 private var mouse: boolean;
     mouse = false;
 private var count: int;
     count = 1;
 private var Minute = 60;
     
 function OnMouseOver ()
     {
     mouse = true;
     }
     
 function OnMouseExit ()
     {
     mouse = false;
     }
 function Update  () {
  var hour: int;
      hour = 0 + Time.time / 60;
  var minute: int;
      minute = 0 + Time.time;
 
     if (Input.GetKeyDown("e") && mouse == true)
     {
     textObject.text = "The time is " + hour + ":" + minute;
     }    
     if (Time.time > 59)
         {
          minute = minute -60;
         }
 }

I was wondering if anyone knew what was wrong with this code

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 wahoosjw · Feb 12, 2013 at 10:12 PM 0
Share

Thanks both these solutions work for me.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Feb 12, 2013 at 02:04 AM

Calculate the minutes like:

 var minute: int = Time.time - hour * 60;

And remove the:

 minute = minute - 60;

Note you will need to do some string padding or formatting or you will get times like 0:7.

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
0

Answer by numberkruncher · Feb 12, 2013 at 02:11 AM

Why not just use this approach:

 private var startTime : System.DateTime;

 function Awake() {
     // Reset timer from start of scene.
     startTime = System.DateTime.Now;
 }

 function OnUpdate() {
     var duration : System.TimeSpan = System.DateTime.Now - startTime;

     textObject.text = string.Format("The time is {0}:{1:d2}", duration.Hours, duration.Minutes);
 }

I haven't tested the above, but this concept should work.

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

10 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

Related Questions

Multiple Cars not working 1 Answer

Where do I assign GUI scripts? 1 Answer

What is wrong with my RockPaperSissors script? 1 Answer

Script outdated i think, Unity 4 - Compiler errors galore 1 Answer

Forward movement Slow? Delta.time? Frame Rate? 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