• Register

Solution:

Where as you know what rotation you want to close at, you can change cameras on time you have reached that rotation.

Generate and initialize a variable outside of the Update method:

private bool isFinishedTurning = false;

Then inspect whether the turn is accomplished in your update method and change cameras if it is complete:

if (rotateHead == true) {
    Quaternion targetRotation = Quaternion.Euler(head.transform.localRotation.x, head.transform.localRotation.y, 0f);
    head.transform.localRotation = Quaternion.Lerp(head.transform.localRotation, targetRotation, 1.0f * Time.deltaTime);

    // Check whether the current localRotation is the same as the target rotation
    if (head.transform.localRotation == targetRotation) {
        isFinishedTurning = true;
    }
}

// If the rotation is complete, swap cameras and disable animation
if (isFinishedTurning == true) {
    cameras[0].SetActive(false);
    cameras[1].SetActive(true);
    anim.enabled = false;
    isFinishedTurning = false;
}

 

posted Jul 4 in c# 17,260 points