- Home /
Setting a max CPS? (clicks per second)
Does anyone know a way to limit an amount of times a player can click a button per second in C#? I was searching around for a while but couldn't find anything on how to set a limit the CPS input.
Answer by Bunny83 · Jan 26, 2019 at 07:51 PM
Well it depends what CPS value range you have in mind and what's more important to you: To never go above the limit or to ensure the user can actually reach this CPS limit.
If you just want to limit the CPS you can use a simple timeout / cooldown variable. So whenever the user clicks you set the timeout to "1/CPS" seconds. So the user can only click again when this timeout is over.
public float CPSlimit = 10f;
float timeout = 0;
void Update()
{
if (timeout > 0)
timeout -= Time.deltaTime;
else if (Input.GetKeyDown(KeyCode.Space))
{
timeout = 1f / CPSlimit;
// Do something
}
}
I have checked the code, but was wondering how the code was going to deter$$anonymous$$e how many times the Left $$anonymous$$ouse Click key is being clicked per second. Also, how would you make a cap so if it reaches over 10 CPS it would put the CPS input for the game back down to 10.
just create a int for getting track of the number of clicks.
Yes, well how would I do that... I cannot transfer Input.Get$$anonymous$$ouseDown to an int so how could I get the active number of CPS for every second. I am a newbie so I need a little help.
Your original question wasn't about counting the number of clicks but to limit the number of clicks the user can make per second. That's what my code does. If you set a CPS limit of 10 (like in my example) the timeout time will be "0.1sec" (1 / 10). So when the user clicks, he can't click in the next 0.1 seconds (or 100 ms). This will limit the max clicks per second to 10
You weren't very clear in the question what actual input method you're using. Do you want to use a key on the keyboard? Or just when the user presses down the mouse button? Or when he actually clicks on a GUI button on the screen? Note that GUI buttons generally react to the mouse up event after it got pressed down. For fast interactions this is usually a bad choice. Anyways you should be more clear about your setup and what input you want to use. I just assumed a button on the keyboard.
Answer by xxmariofer · Jan 26, 2019 at 07:51 PM
hello, i am not native speacker and i am not understanding what cps means, but the easiest way of doing it is just create a coroutine that sets the button interactable to false, waits for desired seconds and set it again to true.
CPS == calls per second (or clicks per second)
just like
FPS == frames per second
Answer by clickgamer155 · Jan 16, 2021 at 03:30 PM
If you need variation like Link given blew. I will assist you to make like this and I also help you to make games like kohi jitter counters Like This
Answer by sopheadave · Apr 30, 2021 at 04:05 PM
Recently did a freelance job for one of my clients who had the same requirement. In his case, he wanted to limit the HPS, which I think is the same as CPS.
Here is a demonstration of the work I am talking about.
In this case, my client wanted to limit the spacebar hits within a specific timeframe. You can apply the same logic here for clicks.
func(){
while (time){
//Get Clicks
}
}
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Input for bluetooth controller? 0 Answers
Player moves too fast diagonally and accelerates too fast diagonally. 2 Answers
How to use Multi-Tap in New Input System for Running? 1 Answer