Zooming In/Out Script? (JS)

I have a script that zooms in or out when “c” is hit but I want to set it so that when ever the mouse wheel is zoomed in or out (like in portal 2) it does so, not when a key is just hit.

Here is my script:

var zoom : int = 20; //determines amount of zoom capable. Larger number means further zoomed in
var normal : int = 60; //determines the default view of the camera when not zoomed in
var smooth : float = 5; //smooth determines speed of transition between zoomed in and default state
private var zoomedIn = false; //boolean that determines whether we are in zoomed in state or not

function Update () {
if(Input.GetKeyDown(“c”)){ //This function toggles zoom capabilities with the Z key. If it’s zoomed in, it will zoom out

zoomedIn = !zoomedIn;

}

if(zoomedIn == true){ //If “zoomedIn” is true, then it will not zoom in, but if it’s false (not zoomed in) then it will zoom in.

camera.fieldOfView = Mathf.Lerp(camera.fieldOfView,zoom,Time.deltaTime*smooth);

}

else{
camera.fieldOfView = Mathf.Lerp(camera.fieldOfView,normal,Time.deltaTime*smooth);

}

}

This is what I use to set my FOV when sprinting and doing other stuff. I forget what the * 10 does, it might be the speed at which it performs the lerp, I honestly forget. Try changing it and playing around.

Camera.main.fieldOfView = Mathf.Lerp(Camera.main.fieldOfView, NEW_FOV, Time.deltaTime * 10);

Hey StickyKeyStudios, this will only make a compiler error, This could be because you told me a C# script while this is JavaScript.

Keep in mind, using field of view can be deceiving as it warps the cameras perspective. Another option is to use position.