Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 toadie-festino · Jul 08, 2015 at 09:23 AM · timerracing

Lap timer not updating best lap milliseconds...not efficient enough?

Hi

I have a lap timer script which currently times the current lap but also stores the players best lap and displays it to them. I store it in playerprefs. the problem I have is that if I go milliseconds faster, the best lap isn't being updated. If I go seconds faster, it is... so 00:09:90 .. if i go 00:09:50 .. it wont update.. as soon as i do a 00:08:++ it will update...

I have included the script here from one of my levels. Hopefully its fairly obvious as to what each bit does... Any ideas?

 #pragma strict
 var myStartTime:float;
 var GameStartTime : float = 0;
 var isStartTime : boolean = false;
 
 var BestTimeText: String;
 var minutes:int=0;
 var seconds:int=0;
 var fraction:int=0;
 var timeText;
 var objecttoshow : GameObject;
 var newSkin : GUISkin;
 
 function Start () {
     if(PlayerPrefs.GetInt("StadiumBestTime") == null || PlayerPrefs.GetInt("StadiumBestTime") == 0){
         PlayerPrefs.SetInt("StadiumBestTime",100);
         PlayerPrefs.Save();
     }
 }
 
 function Update () {
     BestTimeText = String.Format ("{0:00}:{1:00}:{2:00}",PlayerPrefs.GetInt("Stadiumminutes"), PlayerPrefs.GetInt("Stadiumseconds"), PlayerPrefs.GetInt("Stadiumfraction") );
     
 }
 
 function OnGUI() {
     GUI.skin = newSkin;
     GUI.Label (new Rect(Screen.width/2-Screen.width/4,Screen.height/3,Screen.width/2,Screen.width/12),"Best Time: "+BestTimeText);
 
     if(isStartTime)
         GameStartTime =Mathf.Abs( Time.time - myStartTime );
     else
         GameStartTime = 0;
     minutes =GameStartTime / 60f;
     seconds = GameStartTime % 60f;
     fraction = (GameStartTime * 100) % 100;
     timeText = String.Format ("{0:00}:{1:00}:{2:00}",minutes,seconds,fraction);
     GUI.Label (new Rect(Screen.width/2-Screen.width/4,0,Screen.width/2,Screen.width/12),"Time: "+timeText);
     
 }
 
 function OnTriggerEnter (collider : Collider) {
 
     if(collider.tag=="TimeEnd"){
         if(GameStartTime < PlayerPrefs.GetInt("StadiumBestTime")) {
             PlayerPrefs.SetInt("Stadiumminutes",minutes);
             PlayerPrefs.SetInt("Stadiumseconds",seconds);
             PlayerPrefs.SetInt("Stadiumfraction",fraction);
             PlayerPrefs.SetInt("StadiumBestTime",GameStartTime);
             PlayerPrefs.Save();
         }
         Time.timeScale =1;
     }
     
     if(collider.tag == "start") {
         myStartTime = Time.time;
         isStartTime = true;
         yield new WaitForSeconds(0.5);
         objecttoshow.SetActive(false);
     }
     if(collider.tag == "mid") {
         yield new WaitForSeconds(1.5);
         objecttoshow.SetActive(true);
         }
 }
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

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

Race begins when Green light shows 2 Answers

How do I make a lap timer? 2 Answers

Starting timer when I press a key 1 Answer

How can i add a timer to this code 1 Answer

How to make a timer read to the .001 of a second 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