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
1
Question by Coreyf716 · Oct 24, 2012 at 11:01 PM · timefloatframe

Calculate in Seconds not Frames?

 if (reloadTimer) {
         reloadTimer -= Time.deltaTime;
     }
     if (coolTimer) {
         coolTimer -= Time.deltaTime;
     }

The problem is that the values don't stop at zero.

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

2 Replies

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

Answer by Memige · Oct 26, 2012 at 10:46 PM

Okay, a possible problem here is that Time.deltaTime won't necessarily land you on 0. It can, but it's far more likely to jump right past 0 to a negative number. Try this:

 if (reloadTimer) {
    reloadTimer -= Time.deltaTime;
    if(reloadTimer < 0.0f)
    {
        reloadTimer = 0.0f;
    }
 }
 if (coolTimer) {
    coolTimer -= Time.deltaTime;
    if(coolTimer < 0.0f)
    {
        coolTimer = 0.0f;
    }
 }
Comment
Add comment · Show 10 · 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 DoctorWhy · Oct 26, 2012 at 10:49 PM 0
Share

And this is if the reloadTimer and coolTimer are floats.

avatar image Memige · Oct 26, 2012 at 10:51 PM 0
Share

yes, Time.deltaTime returns the seconds since the last frame which will be a small decimal number (hopefully), so it will only be useful if you are using floats.

avatar image Coreyf716 · Oct 26, 2012 at 10:56 PM 0
Share

Yes, that was what kept happening. What is the point of putting 'f' behind the floats?

avatar image DoctorWhy · Oct 26, 2012 at 10:58 PM 0
Share

It casts the usual double (any number with a decimal) to a float. Just remove the "f" from the variable assignment and see what error you get.

avatar image Coreyf716 · Oct 26, 2012 at 11:06 PM 0
Share

There is no error

Show more comments
avatar image
2

Answer by DoctorWhy · Oct 24, 2012 at 11:04 PM

EDIT: Now that you completely changed the question, this answer is useless. But will leave it here anyway...

Integer if that is what you are doing. But that bases it off of the fps, not actual time. Maybe something like this: http://answers.unity3d.com/questions/11939/count-down-timer.html if you want accuracy.

Comment
Add comment · Show 13 · 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 Coreyf716 · Oct 24, 2012 at 11:10 PM 0
Share

It would work, but why would I use an else if?

avatar image DoctorWhy · Oct 24, 2012 at 11:13 PM 0
Share

Oh, woops... ignore that... misread your code... my dyslexia got the better of me...

avatar image Coreyf716 · Oct 24, 2012 at 11:41 PM 0
Share

Ok, so an int would be the better choice. What if I did use a float? How would that effect the game?

avatar image DoctorWhy · Oct 24, 2012 at 11:45 PM 0
Share

It wouldn't look like it effects the game at all to the player. However, if you had, say, a million floats that can be ints ins$$anonymous$$d, you may see lag because integer calculation speed is generally faster than floats.

And maybe this is different now-a-days with modern graphics cards and the speed of floating point math, which I hear is as fast, if not faster than integers. But, in general, if you don't need decimals, I wouldn't recommend using floats.

avatar image Coreyf716 · Oct 25, 2012 at 12:09 AM 0
Share

That makes sense.

Thanks for all of the help.

Show more comments

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

12 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

Related Questions

How does Time.deltaTime provide smoother physics functions? (Frame rate question) 2 Answers

How can I change a float variable over time? 3 Answers

Get time of AudioSource.Clip to System.Date format 1 Answer

time.deltaTime different? varies? 0 Answers

Time Delay Animation 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