鼠标滚轮输入无法统一识别

Mouse scroll wheel input not being recognised in unity

试图让缩放相机脚本工作,但没有成功。我的脚本的其他部分运行良好,除了这个,我认为它与鼠标滚轮有关。

void LateUpdate()
{
    if (!EventSystem.current.IsPointerOverGameObject())
    {     
        if(Input.GetAxis("Mouse ScrollWheel")<0)
        {
            CameraZoom();
        }
    }
}

public void CameraZoom()
{
    if (!EventSystem.current.IsPointerOverGameObject())
    {
        distance = Mathf.Clamp(distance - Input.GetAxis("Mouse ScrollWheel") * zoomFactor, distanceMin, distanceMax);
        RaycastHit hit;

        if (Physics.Linecast(target.position, transform.position, out hit))
        {
            distance -= hit.distance;
        }
    }
}

我只是想让它在我移动鼠标滚轮时缩放,但我需要它是一个 public void 以便我可以从其他脚本访问它,主要是轻松触摸。

尝试将这段代码放在 Update() 而不是 LateUpdate() 中。

void Update()
{
if (!EventSystem.current.IsPointerOverGameObject())
    {     
    if(Input.GetAxis("Mouse ScrollWheel")<0)
        {
            CameraZoom();
        }
    }
}