so im trying to make an aiming mechanic on my game with unity engine, it works well. but the problem is every time the game started, the FOV always become zero. it will be normal again when i press right click on my mouse.
here is my code:
[Header("Zoom")]
public float zoomInFov = 40;
[HideInInspector] public float hipFov;
[HideInInspector] public float currentFov;
public float fovSmoothSpeed = 10;
void Start()
{
hipFov = vCam.m_Lens.FieldOfView;
}
//Aiming
if (Input.GetMouseButton(1))
{
animator.SetBool("isAiming", true);
currentFov = zoomInFov;
}
if (Input.GetMouseButtonUp(1))
{
animator.SetBool("isAiming", false);
currentFov = hipFov;
}
vCam.m_Lens.FieldOfView = Mathf.Lerp(vCam.m_Lens.FieldOfView, currentFov, fovSmoothSpeed *
Time.deltaTime);
please help me, i'd appreciate any advice :)
CodePudding user response:
void Start()
{
hipFov = vCam.m_Lens.FieldOfView;
currentFov = hipFov;
}