I am trying to implement camera zoom using the touchpad on my laptop. Input.mouseScrollDelta.y
only seems to work with a physical mouse.
I read that touchpad events can be handled with private void OnGUI()
which will be called for rendering and handling GUI events (although I’m not sure why a touchpad scroll is classified as a GUI event?).
I tried a few things but I can’t get my script to recognize the two finger swipe on my touchpad as input. Does the new input system have an easy way to handle this as opposed to the legacy system?
Any tips on how to solve this issue would be appreciated!
private void OnGUI()
{
float zoomAmount = 1f;
if (Event.current.type == EventType.ScrollWheel)
{
if (Event.current.delta.y > 0)
{
targetFollowOffset.y -= zoomAmount;
}
if (Event.current.delta.y < 0)
{
targetFollowOffset.y += zoomAmount;
}
}
targetFollowOffset.y = Mathf.Clamp(targetFollowOffset.y, MIN_FOLLOW_Y_OFFSET, MAX_FOLLOW_Y_OFFSET);
float zoomSpeed = 5f;
cinemachineTransposer.m_FollowOffset = Vector3.Lerp(cinemachineTransposer.m_FollowOffset, targetFollowOffset, Time.deltaTime * zoomSpeed);
}