- Home /
How does GetButtonDown-equivalent looks like for Input System ?
Hi everyone this is the first time I use the InputSystem.
I am trying to use a button to switch the camera from FPS to TPS but when I press the action is performed continuously for each frame. I would like the key pressed to work only once as Input.GetButtonDown
. I need it to be pressed, one time only. N.B. I think the correct perform is onRelease
. So in the screen the Trigger Behaviou
is set to Release Only
https://forum.unity.com/threads/input-system-release-only.1293426/ for more details
Here is my code and a screen:
public bool SwitchCamera { get; private set; }
InputActionMap _currentMap;
InputAction _switchCameraAction;
void Awake ()
{
_switchCameraAction = _currentMap.FindAction("SwitchCamera");
_switchCameraAction.performed += onSwitchCamera;
_switchCameraAction.canceled += onSwitchCamera;
}
private void onSwitchCamera(InputAction.CallbackContext context)
{
SwitchCamera = context.ReadValueAsButton();
}
public bool SwitchCamera { get; private set; }
InputActionMap _currentMap;
InputAction _switchCameraAction;
void Awake ()
{
_switchCameraAction = _currentMap.FindAction("SwitchCamera");
_switchCameraAction.performed += onSwitchCamera;
_switchCameraAction.Enable();
}
void onSwitchCamera ( InputAction.CallbackContext ctx )
{
SwitchCamera = !SwitchCamera;
}
Your answer
Follow this Question
Related Questions
GetButtonDown Button-Names ..?! 1 Answer
Input System not executing Unity events 1 Answer
New Input System action returns mouse vector only while holding down a key 0 Answers
OpenXR Continuous Turn and Movement not working 0 Answers
Can an InputAction have binding and compositeBinding at the same time ? 0 Answers