From the course: Advanced Unity 2D: Platformer Player Movement
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Limiting jump - Unity Tutorial
From the course: Advanced Unity 2D: Platformer Player Movement
Limiting jump
- Now we're ready to fix the bug we saw in the previous video, where if you hold down the jump key, the player just keeps jumping. In order to do that, we're going to want to keep track of the time the jump key has been pressed. If it's closer to zero, we know that it's recently been released. If not, we know that it's being held down for a longer period of time. In order to do that, we're going to have to create a new method on the input state, that gives us access to the button hold time that we're tracking. Let's open up the input state class, and at the bottom, we're going to copy the get button value method and paste it below. Let's change this to get button hold time, and we're going to want to change the return value to a float. Next, we'll want to get the whole time property on the state, and finally, if no button state exists, we're going to want to return zero as the value. Now, we'll save this script, and let's go back into our jump script. At this point, we're going to…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.