Search Unity

Having trouble with keyboard input.

Discussion in 'Editor & General Support' started by immortalitybh, Dec 3, 2018.

  1. immortalitybh

    immortalitybh

    Joined:
    Dec 3, 2018
    Posts:
    2
    Hello I'm currently developing a light bike game based on the Tron universe. I am experiencing problems with my input. I'm lead to believe that the problem might be caused by my PC because when I developed on my other PC I never experienced the same input problems that I'm having now. The code looks something like this:


    if (Input.GetKeyDown(KeyCode.A))
    {
    Debug.Log("A Key Pressed");
    BlueBike.transform.Rotate(Vector3.forward * BikeRotateSpeed * Time.deltaTime);
    trig = 2;
    }
    else
    {
    trig = 0;
    Debug.Log("a not down");
    }

    This is a statement that relates to the movement of the bikes in an Update method. I haven't gotten any errors from the script itself. When I press the A key down "A Key Pressed" is not printed to the console yet "a not down" is printed to the console. There was I a point where I didn't experience any input problems on this PC but now I am. Is there anyone has a similar issue like this that can maybe help me?
     
  2. dmennenoh

    dmennenoh

    Joined:
    Jul 1, 2015
    Posts:
    379
  3. Deleted User

    Deleted User

    Guest

    @dmennenoh is right, you need GetKey, not GetKeyDown. GetKeyDown (or Up for what matters) do not stay down over time. See: