0
\$\begingroup\$

I have the following code run in a coroutine.

I would like to know if the last yield return 0 is necessary and why.

Thank you!

private IEnumerator pChangeFoV()
{
    float duration = 0.7f;
    float zValue = 5f;

    for (float t = 0f; t < duration; t += Time.deltaTime)
    {
        float fNew = Mathf.Lerp(_camera.fieldOfView, zValue, t / duration);
        _camera.fieldOfView = fNew;
        yield return 0;
    }
    _camera.fieldOfView = zValue; //make sure we're really where we want to be

    //now do everything that should be done after we're done with this coroutine

    pEnableSomeScripts();

    yield return 0; //is this final yield return 0 required???
 }
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.