- Home /
Input.GetKeyUp for Input.GetAxisRaw
I'm following this tutorial on making a platformer, but instead of using the Input.GetKeyDown("space") to jump I chose Input.GetAxisRaw("vertical") == 1. In the tutorial he uses Input.GetKeyUp("space") to signify when to reduce the vertical velocity.
Is there a way to do this for Input.GetAxisRaw("vertical") == 1 without creating an additional variable?
(tutorial's code snippet)
if (Input.GetKeyUp("space")) {
// Do thing
}
(example of what I don't want to do)
bool wasJumpingInLastFrame;
if (wasJumpingInLastFrame && Input.GetAxisRaw == 0) {
// Do thing after involving additional variable
}
if (Input.GetAxisRaw("vertical") == 1) {
wasJumpingInLastFrame = true;
} else {
wasJumpingInLastFrame = false;
}
So... What do you want to do? And what would be so bad about having an additional variable if it makes writing your code much easier?
Answer by getyour411 · Dec 06, 2016 at 04:02 PM
Change 6 to "Vertical" (case matters for Axes strings, assuming you haven't changed that in your Axes control panel).
I don't see what you are concerned about with the variable - looks like you swapped a hard-coded Input.GetKey(space) with a Player Settings Input.GetAxis.
I was looking for a built in function in unity which does the Get$$anonymous$$eyUp without having to create another variable. In hindsight I guess it's not too bad for there to just be one more.
Your answer
Follow this Question
Related Questions
Input returns 0 until released and pressed again if held down before start of scene 0 Answers
How to handle Key + Mouse Wheel simultaneously? 1 Answer
Player is overjumping (jumping at least twice when it shouldn't) 2 Answers
How can I make a good jumping script? 2 Answers
jumping from ledge problem 1 Answer