I want to have my players movement speed change if the run button is held down. The action is held in a private InputAction runAction; I am unsure on how to have an if statement in update check if the button is being held down and then call a function to change the movement speed.
Can anyone help?
You could subscribe methods to this action, which would be setting a value of a bool field in your class.
Would look something like this:
// ...
private InputAction _runAction;
private bool _isRunning = false;
private void Awake()
{
_runAction.performed += ( c ) => { _isRunning = true; };
_runAction.canceled += ( c ) => { _isRunning = false; };
}
// do stuff ...
The “performed” event is called when you press a button, while “canceled” is called when you release it.
Well not in all cases, but most.