I have ths script that is supposed to make the camera’s FoV to change when you press the right mouse button and return to normal when you release it.
The problem is that it never reaches neither 40 or 60 degrees completely, and after 1-2 presses, it stops working. Any help?
#pragma strict
var cam : Camera;
var weapon : Transform;
function Update () {
if(Input.GetMouseButtonDown(1))
{
weapon.animation.Play("GunAim");
CamFovChange(40);
}
if(Input.GetMouseButtonUp(1))
{
weapon.animation.Play("GunAimEnd");
CamFovChange(60);
}
}
function CamFovChange(amount : int) {
while(cam.fieldOfView != amount)
{
cam.fieldOfView = Mathf.Lerp(Camera.main.fieldOfView, amount, 10*Time.deltaTime);
yield;
}
}