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 Bafelmauk · Jun 20, 2015 at 04:11 PM · c#countercomboaverage

Timer last 5 second counter

Hello i have problem counting delta timer last 5 second counts. i have image for explanation alt text

Word explanation Timer have run 23 seconds and total click in 23 seconds is 72. Last 5 seconds is 20 clicks. i want make so that lable show that last 5 second counts, how i can do it ?. But i dont have idea how to make it so.

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 maccabbe · Jun 20, 2015 at 05:10 PM 0
Share

I would use a queue of times. Each time a player clicks the mouse add the time the mouse was clicked to the queue. Every Update remove all times that are older than 5 second. Then use the queue's length to deter$$anonymous$$e the number of clicks in the last 5 seconds.

avatar image Bafelmauk · Jun 20, 2015 at 09:36 PM 0
Share

okay ty i try figure out how use it now :D maybe i will get work it now if im so pro :D

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Rick Love · Jun 21, 2015 at 11:29 AM

Something like the below will work to keep track of the last 5 seconds of ticks.

However, it will only update once a second, but it will be efficient:

 private int lastWholeSecond;
 private List<int> _ticksDuringSecond = new List<int>(6);
 
 void Update()
 {
     int wholeSecond = (int)Time.time;

     if( wholeSecond > lastWholeSecond )
     {
         lastWholeSecond = wholeSecond;

         // Get rid of the oldest second
         _ticksDuringSecond .RemoveAt(5);

         // Add a new second at the beginning that starts at 0
         _ticksDuringSecond .Insert(0,0);
     }

     // Add a tick to the current second
     _ticksDuringSecond [0]++;

     // Count the seconds from 1-5 
     // (Skip the current second because it is not done)
     int sum = 0;
     for(int i = 1; i <= 5; i++)
     {
         sum += _ticksDuringSecond [i];
     }

     TickCountLabel.text = "" + sum;
 }

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

not resetting the death count on reload 5 Answers

GUI Text Variable Counter In C# 1 Answer

Kill Counter Doesnt Work On Instantiated Objects! 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