How to camera switch...look through cam1 for 10 seconds, then switches to cam 2
Need help with camera switching. Basically, there is a camera in the corner of the room where the player can look around, for 10 seconds, then it switches to a camera on the bed. All I see online is camera switch with code and pressing buttons, but I dont need that. My teacher mentioned something about turning a camera off and the other one on...but I dont see him till tommorow and want to finish it tonight. Really need help due to my deadline being this Friday!
Answer by Cherno · May 03, 2016 at 05:47 PM
Use a Coroutine.
public Camera cam_1;
public Camera cam_2;
public float waitTime = 10f;
void Start() {
cam_2.enabled = false;
StartCoroutine(SwitchCamera());
}
private IEnumerator SwitchCamera() {
yield return new WaitForSeconds(waitTime );
cam_1.enabled = false;
cam_2.enabled = true;
}
Shouldn't line 13 come before 12? Otherwise wouldn't it be possible for a user to see a quick flash of the gray no camera screen (or a lower priority cam)?
That's a good question but the answer is no, it shouldn't / doesn't have to. It all happens within one frame, and only when that frame is finished will any changes become apparent to the user. The camera doesn't render a frame between lines 12 and 13, or between any other lines of code. It all happens after all lines of code have been computed. Only then is the image updated (rendered again), and then it all starts over again for the next frame.
Answer by Mumford-and-Dragons · May 03, 2016 at 06:26 PM
Hey @Cherno, thanks for the code. I am out for a little while, but will be home to test it out. Silly question but will it be as easy as just creating a script and adding the code..voila it works? Or will other steps need to be completed in order for it to work? Specific names at specific parts of the code? e.g 'waitTime ', will it be 'waitTime 10seconds);'?
Your answer
![](https://koobas.hobune.stream/wayback/20220612080106im_/https://answers.unity.com/themes/thub/images/avi.jpg)