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 Nienipanini · Oct 29, 2012 at 02:56 PM · timerminutes

Problem with timer script

Hi all i am having a problem where i looked at for the last few days but i really cannot find out what is wrong. I don't have a clue anymore. I already tried to change a lot but nothing helps.

I have a timer scripts which keeps track of the time during the game. In it is a variable named "looptscript" which is changed outside the timerscript to stop the timer when the player is gameover or returns to the menu etc.

The problem is that the script runs but now after 30 seconds instead of counting on to 31, 32, 33 etc. I makes the time 1.30 so it counts on a whole minut.

Below is my timer script. Other scripts read the time stamp it generates and adjust game difficulty to it.

 import System; 
  
  
 var startTime: float;
 var printtext: String; 
 
 
 var guiTime : float;
 var timemins : float;
 var timesec : float;
 
 var looptscript : boolean = true;
 
 function Update () {
  
     guiTime += Time.deltaTime;
     
     timemins = guiTime / 60;
     timesec = guiTime % 60;
     
     printtext = String.Format ("{0:00}:{1:00}", timemins, timesec); 
     }
     
     
 if (looptscript == false) {
     guiTime = 0.0; 
 }   
 
 
 
 
 
 function OnGUI() {
 
  GUI.Label (Rect (10, 10, 100, 20), printtext);
 
 }
 
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
1
Best Answer

Answer by Karsnen_2 · Oct 29, 2012 at 03:06 PM

Try this one.

The Code:

 var min : int;
 var sec : int;
 var fraction : int;
 var timecount : float;
 var starttime : float;
 var timeCounter : GUIText;
 
 function Start ()
 {
 starttime = Time.time;
 }
 
 function Update () {
 timecount = Time.time - starttime;
 min = (timecount/60f);
 sec = (timecount % 60f);
 fraction = ((timecount * 10) %10);
 timeCounter.text = String.Format("{0:00}:{1:00}:{2:00}",min,sec,fraction);
 }

You might want to check out this answer. I am not really sure what is causing the issue for you.

http://answers.unity3d.com/questions/334877/display-time-at-game-over-scene.html

Comment
Add comment · Show 2 · 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 Nienipanini · Nov 09, 2012 at 03:05 PM 1
Share

I still don't know what went wrong with the other script, because it was working before. But probably something changed... I took your script and it works like a charm.. thank you $$anonymous$$arsnen!

avatar image Karsnen_2 · Nov 09, 2012 at 03:15 PM 0
Share

no problem :)

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

How to stop a Countdown Timer? 1 Answer

making a timer (00:00) minutes and seconds 10 Answers

Countdown Timer Help About putting 0's 1 Answer

Making a timer 1 Answer

Turn seconds into minutes and seconds MM:SS 1 Answer


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