4

Trying to get a zooming camera script to work and it's not. My other parts of the script function fine, except this one and I think it's something to do with mouse scroll wheel.

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;
        }
    }
}

I just want it to zoom when I move the mouse wheel, but I need it to be a public void so that I can access it from other scripts, mainly easy touch.

krlzlx
  • 5,752
  • 14
  • 47
  • 55
Tim Hanson
  • 251
  • 1
  • 5
  • 17

1 Answers1

1

Try putting this code in Update() instead of LateUpdate().

void Update()
{
if (!EventSystem.current.IsPointerOverGameObject())
    {     
    if(Input.GetAxis("Mouse ScrollWheel")<0)
        {
            CameraZoom();
        }
    }
}
Ageonix
  • 1,748
  • 2
  • 19
  • 32