I'm creating a shooting angry birds style game with new input system.
I want to save the mouse position to a variable when the mouse is clicked and released.
Subscribing to the .started event doesn't work. Using .performed, it works with 1 click 2 times, once at the start and once after release.
When I try .canceled it doesn't work too.
private void OnEnable()
{
controls.Gameplay.Shoot.started += _ => PlayerAimingStart();
controls.Gameplay.Shoot.performed += _ => PlayerAimingPerformed();
}
private void PlayerAimingStart()
{
shootingPositionStart = controls.Gameplay.MousePosition.ReadValue<Vector2>(); shootingPositionStart.z = 0f;
}
private void PlayerAimingPerformed()
{
shootingPositionEnd = controls.Gameplay.MousePosition.ReadValue<Vector2>(); shootingPositionEnd.z = 0f;
Vector3 force = shootingPositionStart - shootingPositionEnd;
Vector3 clampedForce = Vector3.ClampMagnitude(force, maxDrag) * power;
bulletGO.GetComponent<Rigidbody2D>().AddForce(clampedForce, ForceMode2D.Impulse);
}