I had a question involving handling buttons being held during a frame with the new input system. I want add the time while the input was held.
On the old system it looked something like this:
time += Time.deltaTime;
My question is about handling something like this with the new input system? I currently have registered actions to my input actions to be called back for the action being performed and cancelled.
_inputActions.PlayerControls.Jumping.performed += Jump;
_inputActions.PlayerControls.Jumping.canceled += Jump;
I believe I have it setup to poll inputs at the start of the frame and not during the physics update so I could technically poll the value and handle it in the update loop since the performed action is called once. However I was wondering if there was a way to handle a held action in a callback or something like that instead of just updating the information when the action is performed and canceled and performing something in the update?
Where you able to figure this out? I see there haven’t been any replies for you.
I kind of lost patience with it and ended up doing this, using the new InputSystem. This is a rough cut and paste, so be aware that some of the variables are defined elsewhere. But I am grabbing key and gamepad input directly, skipping around all that ActionItem stuff.
Also know that I am newer to Unity than most, so my “ideas” probably aren’t the best practices in the end. But this works and it’s easy to understand and adapt. This is from a game that allows both keyboard and gamepad input, and I am reading direct input values from keyboard and game controller. There’s a lot of rotating in my game, which explains all the “rot” stuff.
public class RoverGamepad : MonoBehaviour
[SerializeField] Transform inputSpace = default;
Vector3 axUp, axForward, axRight;
public float rotMult = 36f;
Vector2 rot, kyrot, strot;
float orient, kyorient, storient;
float thrust = 0f;
public float thrustMult = .1f;
float kythrust, stthrust;
var gamepad = Gamepad.current;
if (gamepad == null) return;
strot = gamepad.leftStick.ReadValue();
if (strot.magnitude < .1)
strot = Vector2.zero;
storient = gamepad.rightTrigger.ReadValue();
stthrust = gamepad.leftTrigger.ReadValue();
var keyboard = Keyboard.current;
if (keyboard == null) return;
kyrot = new Vector2(keyboard.dKey.ReadValue() - keyboard.aKey.ReadValue(),
keyboard.eKey.ReadValue() - keyboard.nKey.ReadValue());
kyorient = keyboard.sKey.ReadValue();
kythrust = keyboard.wKey.ReadValue();