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 /
This question was closed Mar 08, 2015 at 11:55 PM by KnightRiderGuy for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by KnightRiderGuy · Feb 21, 2015 at 10:23 PM · c#timertimer-scripttimerscountup

Timer Script Not Keeping Accurate Time?

I have this C# timer script and I only just noticed that for some reason it is NOT keeping accurate time. For instance in the seconds part of the timer it should change the minute number over when it reaches 60 seconds but it does not? Any clue as to why that is? Anyone. Also in one of my previous posts I was trying to figure out how to get this timer to keep time over scene changes, so far no luck with that question either. Here is the timer code:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class timer : MonoBehaviour {
 
 
 
     public Text timerLabel;
     
     private float time;
 
 
     
     void Update() {
 
         
         time += Time.deltaTime;
         
         var minutes = time / 60; //Divide the guiTime by sixty to get the minutes.
         var seconds = time % 60;//Use the euclidean division for the seconds.
         var fraction = (time * 100) % 100;
         
         //update the label value
         timerLabel.text = string.Format ("{0:00} : {1:00} : {2:00}", minutes, seconds, fraction);
     }
 
     //Reset Timer
     public void  ResetTimer(){
         time = 0;
         Debug.Log("Timer Reset");
     }
 
     //Stop Timer
     public void  StopTimer(){
         //Stop Timer Here
 
         Debug.Log("Timer Stopped");
     }
 }
 
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 KnightRiderGuy · Feb 22, 2015 at 02:11 PM 0
Share

I have been looking into trying to add an hours slot to this script, I have tried a few things but not having any luck, my lame experiments with it get strange results. I'm pretty sure it just needs another Var added and then the additional time slot on line 25 but I'm not getting clearly how that is done and the only other examples I have seen are in a differently formatted code.

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by Jessespike · Feb 21, 2015 at 10:45 PM

var minutes = Mathf.Floor(time / 60);

Comment
Add comment · Show 1 · 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 KnightRiderGuy · Feb 21, 2015 at 10:51 PM 0
Share

Yup, that was what it was, thanks Jessespike. now I suppose all this timer needs is an hours slot?

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Unity 5 - Time counter Up script (millisecond precision) UI 1 Answer

Stop and Pause Timer 2 Answers

timer not ticking down 2 Answers

CountDownTimer Help 1 Answer

How to make this display milliseconds? 3 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