How to Zoom in/out using the mouse wheel?

Hi, all! I cant figure it out how to zoom in or out a perspective camera using the mouse wheel. Is there anyone could help?

THX!

You'll need to set up your variables distance and zoomRate, and it depends on your specific camera script, but it will go something like this:

    // Middle ScrollWheel for Distance / Zoom
if(Input.GetAxis("Mouse ScrollWheel") != 0.0)
{
    distance -= (Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime) * zoomRate * Mathf.Abs(distance);

}

Are you referring to an in-game camera?

For a perspective projection, zoom is usually effected by modifying the field of view. The camera field of view can be modified directly via scripting, so what you would most likely want to do here is increase or decrease the field of view as appropriate in response to mouse wheel events, while keeping it constrained to some reasonable range.