- Home /
How to detect input being hold in new Input System
I have an InputAction in my script, and I use .triggered to detect when the key/gamepad button was pressed that frame, just like through code you can do Gamepad.current.aButton.wasPressedThisFrame.
How can I also check if it's pressed? Like Gamepad.current.aButton.isPressed.
Also, is there an equivalent of Key for gamepad buttons?
//theory code
var gamepadInput = aButton;
if (Gamepad.current[gamepadInput].isPressed)
//do something
Answer by bubzy · Jun 27, 2021 at 08:38 AM
void HoldMe(InputAction.CallbackContext context)
{
if(context.performed) // the key has been pressed
{
//dothething
}
if(context.canceled) //the key has been released
{
//stopdoingthething
}
}
more about the states are here, I use the inspector to assign callbacks, theres probably a more clever way to do it, but this works ok for me. hth https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Actions.html
Answer by Simmons857 · Jun 26, 2021 at 02:09 PM
First, note that when you create controls and have a C# class auto-generated, you need to have your class inherit that. Your controls class is called PlayerInputActions. I don't see the "Action Map" name, so I will use mine. In the GUI, mine is called "AvatarDefault". The action is called "Jump". If you inspect the auto-generated C# class, you will find the namespace, interface, and methods. My action map becomes an interface when generated, and is named IAvatarDefaultActions. Since you don't list your ActionMap name, I will use mine. Replace it with yours in your code.
Hello @Simmons857 I don't fully understand your answer, can you explain again?
Your answer
Follow this Question
Related Questions
New Unity Input System Getting continuous input 1 Answer
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
How do I standardize my game's input to different types of controllers? 1 Answer
how can I assign and use different controller schemes for a single keyboard? 0 Answers