Short answer:
private void pChangeFoV()
{
float zValue =70f;
for (float t = 0f; t < FoVDuration; t += Time.deltaTime)
{
float fNew = Mathf.Lerp(_camera.fieldOfView, zValue, t / FoVDuration);
_camera.fieldOfView = fNew;
}
_camera.fieldOfView = zValue;
}
I just removed the yield keyword, since it is a special keyword that states that the statement, this case a method, is an iterator (IEnumerator, or T Generic IEnumerator).
Nonetheless, by turning it into void, you are losing the smooth FOV change you wanted to achieve. To turn the functionality into a void, I'd do something like this:
private bool smoothChange = true;
private float zValue = 70f;
private float t = 0.0f;
private void Update()
{
if(smoothChange) pChangeFoV();
}
private void pChangeFoV()
{
_camera.fieldOfView = Mathf.Lerp(_camera.fieldOfView, zValue, t);
t += Time.deltaTime / FoVDuration;
if(t >= 1.0f)
{
_camera.fieldOfView = zValue;
smoothChange = false;
}
}
Although I'd rather use coroutines for these kinds of functionalities.