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