My part of the input code looks like this:

void Update()
    y_input = Input.GetButtonUp(StaticStrings.Y);

    delta = Time.fixedDeltaTime;

void GetInput()
    vertical = Input.GetAxis(StaticStrings.Vertical);
    horizontal = Input.GetAxis(StaticStrings.Horizontal);
    b_input = Input.GetButton(StaticStrings.B);
    a_input = Input.GetButton(StaticStrings.A);
    y_input = Input.GetButtonUp(StaticStrings.Y);
    x_input = Input.GetButton(StaticStrings.X);
    rt_input = Input.GetButton(StaticStrings.RT);
    rt_axis = Input.GetAxis(StaticStrings.RT);

    if (rt_axis != 0)
        rt_input = true;

    lt_input = Input.GetButton(StaticStrings.LT);
    lt_axis = Input.GetAxis(StaticStrings.LT);

    if (lt_axis != 0)
        lt_input = true;

    rb_input = Input.GetButton(StaticStrings.RB);
    lb_input = Input.GetButton(StaticStrings.LB);

    rightAxis_down = Input.GetButtonUp(StaticStrings.L) || Input.GetKeyUp(KeyCode.T);

    if (b_input)
        b_timer += delta;

    d_x = Input.GetAxis(StaticStrings.Pad_X);
    d_y = Input.GetAxis(StaticStrings.Pad_Y);

    d_up = Input.GetKeyUp(KeyCode.Alpha1) || d_y > 0;
    d_down = Input.GetKeyUp(KeyCode.Alpha2) || d_y < 0;
    d_left = Input.GetKeyUp(KeyCode.Alpha3) || d_x < 0;
    d_right = Input.GetKeyUp(KeyCode.Alpha4) || d_x > 0;

The problem is that my Y button is connected with the function of changing from one hand weapon to two hand weapon, but the Y button only works a few times in game!

e.g., I have to press about 3 times then it works.

How do I solve this?

  • 1
    \$\begingroup\$ I'm unable to reproduce the problem you describe with the code you're shown here. Can you create a new project and add to it the bare minimum scripts & components needed to display this issue, and share with us the complete recipe for recreating it? \$\endgroup\$ – DMGregory Jan 15 at 18:49
  • \$\begingroup\$ Is it your intention to set y_input in both Update and GetInput? \$\endgroup\$ – Tashus Jan 15 at 20:43
  • \$\begingroup\$ Are you by any chance querying the input from FixedUpdates elsewhere in the game ? FixedUpdate is often called more frequently than Update. It can be called multiple times per frame, if the frame rate is low and it may not be called between frames at all if the frame rate is high. \$\endgroup\$ – Omar Guendeli Jan 16 at 6:08
  • \$\begingroup\$ Where do you call GetInput()? I guess it's a race condition between GetInput() and update() \$\endgroup\$ – JeffUK Jan 16 at 13:59
  • \$\begingroup\$ Thank you guys for all the answers ! It's the problem with Update & FixedUpdate that I didn't think of. \$\endgroup\$ – Young Gilgamesh Jan 17 at 7:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.