How to do this once in Update?

private int directions = 1;
var keyboard = Keyboard.current;

if (keyboard.shiftKey.isPressed)
        {
            directions++;

            if (directions == 5)
            {
                directions = 1;
            }

        }

I want to add 1 to directions every time the shift key is pressed. Since I need to check the key press, I have to do it in update, but in update this code is executed multiple times and the directions goes all the way to 4 before going back to 1.

How do I make it so that every time the shift key is pressed, directions is added by 1 and only 1? Thanks in advance. :slight_smile:

Try .wasPressedThisframe instead of isPressed

1 Like

Brilliant! It works thanks so much! :smile:

1 Like