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\$
3
\$\begingroup\$

Use wasPressedThisframe instead of isPressed. :)

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.