Im having difficulties in how to get around Input.GetKeyDown being triggered multiple times.
According to the documentation, it seems as it is the automatically repeated keypress settings “at the end user”. That is neat-o and all, but how can i work around it? Is there a way to distinguish between an auto-repeated keystroke and the actual “initial key being pressed down” event?
e.g. say i have the code below; pressing and holding space will “Jump” untill you release it.
public KeyCode Jump //Set to Space
void Update () {
if (Input.GetKeyDown(Jump)) {
//Jump
}
}
Not sure what you mean; GetKeyDown can not fire again until the key is released, as the docs say. “It will not return true until the user has released the key and pressed it again.” Either you have the script attached multiple times, or you might have a keyboard malfunction.
Like everyone (and the documentation) has said, it fires only during the frame the key press started. Do you maybe have this script attached to 7 different objects in the scene? Can you share some code and/or screenshots of your project with us?
I had the same problem, and after ten minutes of fiddling, I found a solution that worked for me: When I changed my FixedUpdate to an Update it registered perfectly. Hope this can help somebody else
If you’re curious on the specifics as to why I recommend the following thread. Basically though the short story of it is that the function doesn’t run at a fixed interval but rather runs as much as it needs to right before the next update occurs to catch up (eg if it’s behind five intervals, it’ll run five times back to back next time it’s scheduled to run).