I am transitioning to the new movement system and am having trouble figuring out how to move the camera when a mouse button is pressed and held.
Here’s how I did it before:
private void Update()
{
// Get the position of the mouse when a middle click occurs
if (Input.GetMouseButtonDown(2))
{
_dragOrigin = cam.ScreenToWorldPoint(Input.mousePosition);
}
// If the MMB is still held down, calculate the distance and move the camera
if (Input.GetMouseButton(2))
{
Vector3 difference = _dragOrigin - cam.ScreenToWorldPoint(Input.mousePosition);
cam.transform.position += difference;
}
}
I have tried doing something similar in the new input system but it doesn’t work:
public void OnMMB(InputAction.CallbackContext context)
{
if (context.phase != InputActionPhase.Started)
{
// Get the position of the mouse when a middle click occurs
dragOrigin = cam.ScreenToWorldPoint(Mouse.current.position.ReadValue());
}
else
{
// If the MMB is still held down, calculate the distance and move the camera
Vector2 newPosition = cam.ScreenToWorldPoint(Mouse.current.position.ReadValue());
Vector3 difference = dragOrigin - newPosition;
cam.transform.position += difference;
}
}
Here is how I set this up inside the Input editor:
The Action Type
of the action is Button
.