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 avtar109 · Apr 21, 2015 at 06:17 PM · javascripttimeplayerprefs

Help With Quickest TimeScore

I'm trying to save the time in which it took to complete the level and then after that if the beat there time i want it to save that too, i have tried using player prefs but i just carnt figure it out.
Any help would go a long way thank you.
The script im using for the time is below for you to look at if it helps figure out.


 var intsec : int; //this variable is to Count in intergurs which basically means counting in whole number such as 1, 2, 3  
 var minutes = 0; //this variable Counts the minutes  
 var seconds; //this variable Counts the Seconds  
 var TimeScore : TextMesh; //Printing the time since level loads  
 var TimeText = "Time: 0"; //Adding Extra text to the time so that it displays Time:  
 //Variables for Counting Coins  
 var PlayerScore : int; //this is a variable that can be incremented by whole numbers to count the coins  
 var ScoreText = "Coins: 0"; //Adding Extra text to the Coins so that it displays Coins:  
 public var other : GameObject; //this is so that the coin disappears when it collides with the player  
 var CoinScore : TextMesh; ////Printing the Coins When Collected  
 var highscore : int;  
 var CurrentLvl : int;  
   
  function Update() { //Updating continuously  
  sec = sec + Time.deltaTime; //Counts the seconds since object spawn  
  intsec = sec; //turns the sec variable from a float which is things like 4.0, 5.0 to an int like 1, 2, 3, 4  
    
   if(intsec < 10) //this is saying that if the intsec variable is more than 10 do the statement below  
   {  
    seconds = "0"+intsec;   
   }  
   else  
   {  
    seconds = intsec;  
   }  
    
   if(intsec >= 60)  
   {  
    minutes++;  
    sec=0;  
   }  
     
   TimeText = "Time: " + minutes + ":" + seconds;  
  {  
  TimeScore.text = TimeText;  
  }  
 {  
  CurrentLvl = Application.loadedLevel;  
     PlayerPrefs.SetInt("CurrentLevel", CurrentLvl);   
     }  
     {  
     if (CurrentLvl == 1 && PlayerPrefs.GetInt("CoinTotalLvl1") < PlayerScore) {  
     PlayerPrefs.SetInt("CoinTotalLvl1", PlayerScore);    
     }  
     {  
     if (CurrentLvl == 1 && PlayerPrefs.GetInt("Lvl1Comp") == 1){    
     PlayerPrefs.SetInt("MinutesLvl1", minutes);  
     PlayerPrefs.SetInt("SecondsLvl1", intsec);  
     }  
   }  
 }  
 }   
 //Coin Counting and Printing out number  
 function OnTriggerEnter2D(other : Collider2D){  
 if (other.tag == "coin"){  
     PlayerScore +=1;  
     ScoreText = "Coins: " + PlayerScore;  
     CoinScore.text = ScoreText;  
     other.gameObject.active = false;  
 }  
 }  
 
   

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 hbalint1 · Apr 21, 2015 at 09:17 PM 0
Share

please edit your question with: select all your code and format it as code with the little button which has 0s and 1s on it or with Ctrl+$$anonymous$$. And could you provide more information? what is working and what is not? you can't store the scores or the time? you can't display them? we can help you more if you specify your question :)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to save and display players times using Playerprefs in Javascript? 1 Answer

[SOLVED] Help with PlayerPrefs.SetInt 1 Answer

Time.deltaTime not consistent over time 1 Answer

Breathing sound effect using timers 1 Answer

Updating an array indices dynamically 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