Input.GetButtonDown("Jump"); in Unity does not work for space key

Viewed 11659

I know this question has been asked and answered before but in my case, the answers just won't cut it. No answer I have looked at before was able to solve this and even in the Unity forum, I couldn't find useful information. In Unity, I'm trying to build a 2D game, nothing big.

I am trying to set up my movement-script and horizontal movement worked like a charm. But jumping does not work, at least when the button is assigned to Space. Here is my code so far:

void Update() {
    if (Input.GetButtonDown("Jump")) {
        Debug.Log("Jump!");
        rigidBody.velocity = new Vector2(rigidBody.velocity.x, jumpSpeed);
    }
}

It is -as you can tell- really simple. I tried to assign another key to Jump. With the E button everything went fine and my character jumped. But when using the Space, it did not work. Here's an image of my input manager:

Picture of input manager

Notice that I don't have a second Jump option configured. This was where I used the E key.


(I am using Linux Mint Tricia 19.3 if that gives any further information)

2 Answers

As an alternative you could use if (Input.GetKeyDown(KeyCode.Space)) maybe the issue is how the Jump button is set up, but nothing stands out to me.

I believe you can use GetKeyDown and KeyCode to solve your problem. Your code can be modified to use these functions. I have improved your code down below. Just make sure that KeyCode.Space is not assigned to any other key.

void Update() {
    if (Input.GetKeyDown(KeyCode.Space)) {
        Debug.Log("Jump!");
        rigidBody.velocity = new Vector2(rigidBody.velocity.x, jumpSpeed);
    }
}

I also have some scripting docs for you:

Related