# How to do this once in Update?

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 up 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. :)

private int directions = 1;

var keyboard = Keyboard.current;

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

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

}


Use wasPressedThisframe instead of isPressed. :)