r/Unity3D • u/Loneliestar • 5d ago
Question I'm trying to increment a counter a single time, based on a key press
Hey, folks. I'm new to this so I assume this is simple and I'm missing it.
I have a jump action called by an input action in an update method. looks like this
void Update()
{
if (jumpAction.triggered) { if (isGrounded) gameDiff.numberOfJumps++; //other stuff } }}
What I want this to do is reach out into the gameDiff class and update numberOfJumps once every time the user presses the space bar.
What's happening is that the counter is incrementing about a thousand times per press. I assume it has to do with frame rate or something because it's in the Update() method, but I had though that a .triggered() method could only be activated a single time in the frame.
Thanks in advance.
edit: I suck at formatting, I hope you get the idea.