camera switch not working

hey guys this script i got does not work i want to switch view from camera 1 to camera 2 afrter 10 sec but i cant get it to work can you hepl me please

var waitTime = 10;
var numberOfCameras = 7; 

function Start() {        
    for (var i = 0; i<=numberOfCameras;i++) {
        var oldCamera = GameObject.Find("Camera"+(i-1));
        var newCamera = GameObject.Find("Camera"+i);

        oldCamera.active = false;
        newCamera.active = true;

        yield WaitForSeconds(waitTime);
    }
}

Do you have a camera called Camera-1 ? Or do they start with Camera0? Because this script wants to start with Camera-1 and go to Camera7

It's because you're disabling the game object, so you can't find it the next search. You also seemed to have a very odd for loop. I changed so it looks for

  • Camera0
  • Camera1
  • Camera2
  • Camera3
  • Camera4
  • Camera5
  • Camera6

Try storing them in a list instead:

import System.Collections.Generic;

var waitTime = 10;
var numberOfCameras = 7; 

function Start() {

    // 1. Find all cameras. 
    // You probably want to disable them all as well, 
    // so no other camera is active.
    var cameras = new List.<GameObject>(numberOfCameras);
    for (var i = 0; i < numberOfCameras; ++i) {
        cameras.Add(GameObject.Find("Camera"+i));
        cameras*.active = false;*
 *}*
 *// 2. Loop through them and toggle active.*
 *var oldCamera : GameObject;*
 *for (var newCamera in cameras) {*
 *if (oldCamera) oldCamera.active = false;*
 *if (newCamera) newCamera.active = true;*
 *yield WaitForSeconds(waitTime);*
 *oldCamera = newCamera;*
 *}*
*}*
*```*

Well, the simple answer to your problem is that your SetActive statement should be oldCamera.SetActive(false)