Clicks per second in realtime

Hi all,

I’m making a simple game where you need to click as faster as you can to keep the player’s velocity. I’d like the player to know his click ratio (number of clicks he is able to do per second) in realtime before he reach the goal but I don’t really know how to approach the solution.

Could somebody give me a tip?

Thanks!

You can use Input.GetMouseButtonUp to get the clicked event and record the clicks into a variable.

Have a variable that collects the clicks (every time user clicks, increase it by one).
Remember interval start time:
long startTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;

Now you have what you need. If you want to refresh the APM every second, you take current time, subtract startTime and see if 1 second has passed. If it did, return the counter and restart the process.

Hello,

One way to approach this would be to use a time-based sampling rate. This means that you would calculate the player’s click ratio at fixed intervals, and then display it to the player in real-time.

Another option would be to use a frame-based sampling rate. This means that you would calculate the player’s click ratio at the start of every frame, and then display it to the player in real-time.

Which approach you use will depend on your game’s specific requirements. Whichever approach you choose, make sure that you are accurately measuring the player’s click ratio. This means taking into account things like lag and latency.

You can see how clickspersecond.com is worked on the same principle. It samples the mouse position at a fixed rate and then calculates the number of clicks that were made in between those samples.

I hope this information is helpful! Thank you for your question.