Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Whiteleaf · Mar 18, 2016 at 11:48 PM · unity 5timerfloat

My float is always adding 1f to it even with no code telling it to

I'm making a timer, and beware since I've never done it before a lot of this code is taken from examples online. In the examples the people gave it seemed to work fine, but for me my 'minutes' float seems to add an extra 1 to it.

If you're not catching on, here's what I mean. My game starts out with 6 minutes, and it subtracts from there on out. In fact, the code works perfectly fine besides this problem. So when the game starts, I set my ui text to be equal to the timer which I've specified(works nicely). I print out the time in the console, and even though the time is right, 5:59, my text reads "6:59". And here's the weird thing--once it reaches "6:30" it adjusts itself to the correct time, "5:30".

This is code for calculating the time. I don't know why it's adding 1 to the minutes--but hopefully you can help me out!

 float guiTime = goalTime - Time.time;
 
             //print (Time.timeSinceLevelLoad);
 
             float mins = (guiTime / 60);
 
             print (mins);
 
             float sec = (guiTime % 60);
 
             //timerText.text = mins.ToString("f0") + ":" + sec.ToString("f0");
 
             timerText.text = string.Format("{00:00}:{00:00}", mins, sec);
 


some info: goalTime is set to Time.time + winningSeconds in Start(). (winning seconds is 360 seconds for 6 minutes). I've also tried using Time.timeSinceLevelLoad, as you can see and it does not seem to fix the issue.

I hope someone can help me with this, if you need any more information you can ask me! Thanks!

Comment
Add comment · Show 2
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 Fredex8 · Mar 19, 2016 at 12:14 AM 2
Share

Floats in text strings get rounded.

This question sounds like the same issue so the answer will probably work too.

avatar image Whiteleaf Fredex8 · Mar 19, 2016 at 01:40 AM 0
Share

Thank you, works great.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Whiteleaf · Mar 19, 2016 at 01:41 AM

The answer is what Fredex8 said in the comments, thanks!

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

65 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 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 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 avatar image avatar image

Related Questions

Timer float not evaluating correctly when I check if it's less than another number 3 Answers

How save playerprefs timer 0 Answers

Button still not appearing 0 Answers

"Object reference not set to the instance of an object" 0 Answers

Need thinking event, during time it takes to smtpserver.send 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