To accomplish zoom with the mouse wheel, you have to listen to Input.GetAxis("Mouse ScrollWheel"). :) It returns a float that indicates the direction you scrolled in. Scrolling up is positive, down is negative.
In my script, I'm using a fixed amount every time, so I'm not using the actual value of the float, just its sign to determine direction. I also needed to move the camera, not just change its FOV to zoom, so my script looked a little different than the below. I tried to modify it a little so it should match something like what you need.
The lerping is done over 5 frames to zoom smoothly instead of jumping the FOV back and forth the full amount. If you don't need smoothness, you can just add or subtract a fixed amount every time.
float mouseScrollDir = Input.GetAxis("Mouse ScrollWheel");
int lerpCounter = 6;
Wow, I think you're the first person on this site that used Lerp in the way it's meant. Everyone uses the actual value as startvalue and a fix timestep (Time.deltaTime) but that causes the lerping to get slower at the end. That's also a nice effect but not "linear interpolation". Even worse if someone use slerp that way. That will completely "destroy" the advantage of slerp.
Thanks. :-D I can't take credit though, I had to research how it worked, and some other thread explained it to me the right way. If I were to be perfectionist about it, the lerpCounter should really start from 1 and not 0; otherwise, the first call to Lerp ends up setting cam.fieldOfView to the same as its start value. :P
Wow, I think you're the first person on this site that used Lerp in the way it's meant. Everyone uses the actual value as startvalue and a fix timestep (Time.deltaTime) but that causes the lerping to get slower at the end. That's also a nice effect but not "linear interpolation". Even worse if someone use slerp that way. That will completely "destroy" the advantage of slerp.
– Bunny83Thanks. :-D I can't take credit though, I had to research how it worked, and some other thread explained it to me the right way. If I were to be perfectionist about it, the lerpCounter should really start from 1 and not 0; otherwise, the first call to Lerp ends up setting cam.fieldOfView to the same as its start value. :P
– CHPedersen