1

I cannot detect if space-bar key was pressed, I have following code:

void Update() {
  // Working
  if (Input.anyKeyDown) {
    Debug.Log("anyKeyDown");
  }

  // Not working
  if (Input.GetButtonDown("Jump")) {
    Debug.Log("GetButtonDown - Jump");
  }

  // Not working
  if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown("space")) {
    Debug.Log("KeyCode.Space");
  }

  // Working
  if (Input.GetKeyDown(KeyCode.A)) {
    Debug.Log("A");
  }
}

I can detect if e.g. A was clicked but its not working for Input.GetButtonDown("Jump") or for Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown("space")

Below you can see image from my console:

enter image description here

I am using default unity Input Manager settings, I can see two Jumps configured:

enter image description here enter image description here

2
  • What happens if you merge the 2 jumps into one, using the Alt positive button? Commented Jul 24, 2020 at 9:08
  • Not working either, basically if I changed Positive button for Jumps to any other character e.g. a, I can detect it by Input.GetButtonDown("Jump"). Looks odd. There is info note Consider using new Input System Package instead, maybe I will try go this direction Commented Jul 25, 2020 at 11:29

3 Answers 3

1

Maybe do not use 2 Jumps declarations in the input editor. Make one and select its axis to X.

if (Input.GetKeyDown(KeyCode.Space))
{

}
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, have it in my code snippet: Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown("space")
0

Have you considered using

if (Input.GetKeyDown("space"))
    {
        Debug.Log("space key was pressed");
    }

instead?

4 Comments

Yes, have it in my code snippet: Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown("space")
Oops, thats on me. In that case my only guess is that it's caused by having 2 inputs with the same name. If you change the latter to something like "JoystickJump" and just add that one as an OR in your IF statement, it may work. Just quessing tho
Also, maybe you also need to fill out the descriptive name of the input
Also tried this, changed name of one the input but still without success.
0

try using CrossPlatformInputManager

if (CrossPlatformInputManager.GetButton("Space")) {
    Debug.Log("Jump pressed");
}
  • in Input Manager you can add a secondary button for the same input, like your "joystick button 3" on the first Space input as "Alt Positive Button" (Alternative), so no need to have 2 Space Inputs there.
  • why on one Space input you have the "Axis" as "Y Axis" and on the other as "X Axis"? use "X Axis" for both instead.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.