Question

void Update()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
Debug.Log(“Up Arrow key was pressed.”);
}
else if (Input.GetKeyDown(KeyCode.DownArrow))
{
Debug.Log(“Down Arrow key was pressed.”);
}
else if (Input.GetKeyDown(KeyCode.Return))
{
Debug.Log(“You hit enter.”);
}

}

}

this is the code i have but it still let me hit all 3 buttons at once what am i missing?

Hi,

Please add Time.frameCount to your Debug.Log method calls. Here is an example: Debug.Log(Time.frameCount + “---- Up Arrow key was pressed.”);

Update gets called once per frame.

Test your game again. What is the output in your console?

thanks that helped alot

You’re welcome. :slight_smile:

Did you understand why your code is working as it is supposed to be?

I was having the same issue and tried adding this to my code and all it did was add a frame counter to the “button pressed” output. it is still allowing me to press 2 buttons at the same time.

Could you please share a screenshot of your console with the messages in it?

Not to Highjack this thread… but I am having the same issue. I followed the advice above, by adding the Time.frameCount + to my code… but it does not seem to have done anything. The first attempt at multi button press it stops it, but after that it still allows me to press 2 or 3 buttons simulataneously.

(Edit: note- I originally was using H & L, as my input, but when I could still press multiple buttons I changed it just to make sure it wasn’t the buttons I was using. That is why the text say L and H, in the instructions.)

Button presses

After further searching I found two answers to my question (for anyone interested)…
The first and most pertinent: The frame numbers added (with Time.frameCount) show in fact it is a speed issue, and not a coding issue. So if youre having this issue, look at the frame numbers in the console…

And second, if you want the code to function the way I believe most people will feel it intended, there is another post that has the coding to accomplish this at Version that does not allow new input until key is physically released. Good Coding. :slight_smile:

Thanks a lot for sharing the link. :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms