- Home /
using new input system, how do I get a result similar to Input.GetButtonDown?
I am currently using the new input system and almost everything is set up, except the mouse button. I use the InputActionReference
called rightClickControl
and this is all set up correctly using OnEnable()
and OnDisable()
.
The issue I am having is that when I click my mouse, two inputs are registered, one on the mouse down and one on the mouse release. If i use the below code it works, but if i change triggered
to started
(unity docs say started
and performed
both register once, and triggered
does it twice for buttons) i get an error, and i am trying to get all of this set up before i move on to learning anything to do with delegates and events. i wanna keep my game as readable as possible without jumping into the deep end with delegates and events.
Is there any way i can fix this? is there a property of InputActionReference.action
that i am missing? thank you in advance, this community is flawless and so helpful. please bear in mind that my other controls (movement etc) work using this system and i don't want to scrap the work i put in to making it work.
public void testFunction()
{
if (rightClickControl.action.triggered)
{
Debug.Log("Mouse Button Down");
}
}
Answer by Razputin · May 21, 2021 at 01:27 AM
set a bool true on click false on cancel click
mine is with events and yours isn't but it should still be roughly the same, can you post the error you're getting?
private void Update()
{
if (isFiring)
{
Firing();
}
}
public void Fire(InputAction.CallbackContext value)
{
if (value.started)
{
isFiring = true;
}
if(value.canceled)
{
isFiring = false;
}
}
public void Firing()
{
//fire the gun
}
}
I can't check this on my system until I return to my laptop in 8 hours but by reading it, am I right in thinking that this is a constant input whenever it's true as opposed to a one time input? Just trying to achieve a one time input if this is possible. Thank you for your answer nonetheless it's very helpful still
oops I was thinking getbutton,
get button down would be to just put the method in value.started
if (value.started)
{
Firing();
}
It doesn't seem to work for some reason. when i change .triggered to .started, here is the error i get:
The event 'InputAction.started' can only appear on the left hand side of += or -= [Assembly-CSharp]csharp(CS0079)
Sorry to take up so much of your time so far, something just isn't exactly clicking for me.
Your answer
Follow this Question
Related Questions
Can GetKey/GetKeyDown/GetKeyUp all return true in the same frame? 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Read analog stick input without using the Input Manager 1 Answer
where is package manager Unity 2020.3.10f1,package manager is missing Unity 2020.3.10f1 0 Answers
Get x/y joystick axis from hatswitch? 0 Answers