[英]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.
我创建了动作并且它正在触发,但值永远不会变回 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.为什么 sprint 正常工作,当按下它时它变为真,而当它释放时它会触发一个新事件说该值为假。
However the mouse attack only returns true and then never goes back to false.然而,鼠标攻击只返回 true,然后永远不会返回 false。 There is no event fired when I release the left mouse button.
当我释放鼠标左键时没有触发任何事件。
Try changing it to AttackInput(value.isReleased), and change it so it fires when false.尝试将其更改为 AttackInput(value.isReleased),并将其更改为在 false 时触发。
The new input system is event driven/focused, unlike the old Input class.与旧的输入 class 不同,新的输入系统是事件驱动/聚焦的。
Hook into the canceled
event of the input.挂钩输入的
canceled
事件。
inputs.Attack.canceled += (ctx) => StopAttacking();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.