Swapping cameras for duration of animation, buggy results.

Hi,
I’m trying to swap cameras for the duration of the animation on CameraTwo.

And then return control to the First Person Controller. I tried creating a Coroutine to make a WaitForSeconds for the length of the animation.

The results are buggy.

Any code advise would be great.

public class CameraSwap : MonoBehaviour
{
    public GameObject AirPlane;
    public GameObject FirstPersonController;
    public GameObject CameraTwo;



    // Use this for initialization
    void Start()
    {
      
     
    }

    //Update is called once per frame
    void Update()

    {
        if (AirPlane == null)
        {
            FirstPersonController.SetActive(false);
            CameraTwo.SetActive(true);
            CameraTwo.GetComponent<Animation>().Play("CameraZooom");
            StartCoroutine("Wait");
        }
    }
    IEnumerator Wait()
    {
        yield return new WaitForSeconds(5);
        CameraTwo.SetActive(false);
        FirstPersonController.SetActive(true);
    
}
}
}

your code is being called every frame. move it to start or better yet, have the animator deal with all of that. you can place a script on the same gameobject as the animator and have it call functions when you like.

1 Like

Why don’t you just set a function at the end of the animation that swaps the Depth’s of the cameras and do all the other things that need to be done?

1 Like

Thanks for the feedback.

You’re welcome, hope you can handle it out now, let the forum know :slight_smile: