ViktorMS
ViktorMS

Reputation: 1351

Detect mouse released in Unity new input system

I am using the new input system but I cannot seem to get the mouse clicks to behave correctly.

Im trying to implement an attack with the left mouse button. I created the action and it is firing, but the value never turns back to false.

        public void OnSprint(InputValue value)
        {
            SprintInput(value.isPressed);
        }

        public void OnAttack(InputValue value)
        {
            AttackInput(value.isPressed);
        }

Why is the sprint working normally, when pressed it goes to true, and when released it fires a new event saying the value is false.

However the mouse attack only returns true and then never goes back to false. There is no event fired when I release the left mouse button.

enter image description here

Upvotes: 1

Views: 3625

Answers (3)

ViktorMS
ViktorMS

Reputation: 1351

I changed the Action Type from Button to Pass Through and now it is firing true when mouse is pressed and false when released.

Action type pass through

Upvotes: 1

hijinxbassist
hijinxbassist

Reputation: 4701

The new input system is event driven/focused, unlike the old Input class.

Hook into the canceled event of the input.

inputs.Attack.canceled += (ctx) => StopAttacking();

Upvotes: -1

Jonathan
Jonathan

Reputation: 1

Try changing it to AttackInput(value.isReleased), and change it so it fires when false.

Upvotes: -1

Related Questions