Hello everyone,
I’m using the new Input system with code.
I checked the “Generate C# Class” checkbox, and have a code like this (ignored some irrelevant code):
public class PlayerController : MonoBehaviour
{
private InputSystemSettings _inputControl;
private int jumpCounter;
private Rigidbody2D _rb;
private void Awake()
{
_inputControl = new InputSystemSettings();
_inputControl.Player.Jump.performed += JumpPerformed;
jumpCounter = 0;
}
private void Start()
{
_rb = GetComponent<Rigidbody2D>();
}
private void OnEnable() { _inpputControl.Enable();}
private void OnDisable() { _inputControl.Disable();}
private void JumpPerformed(InputAction.CallbackContext context)
{
_rb.velocity = new Vector2(_rb.velocity.x, jumpForce);
jumpCounter += 1;
Debug.Log(jumpCounter);
}
}
so I expect that when I press the jump button (space bar), the console will output 1, and then if I press the jump button again, it will output 2.
However, when I press the jump button, the console outputs 1, and then when I press the jump button again, the console outputs 1 again. if I continue to press the jump button, the console outputs 2, 3, 4, 5…
That means if I press the button 5 times, the output is 1, 1, 2, 3, 4
so is this a new Input system bug? or did I use it in the wrong way?
Any help is appreciated.