0
\$\begingroup\$

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;
            }

        }
\$\endgroup\$
0

1 Answer 1

3
\$\begingroup\$

Use wasPressedThisframe instead of isPressed. :)

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .