Change between two cameras . what is wrong with it. not working properly

var cam1: Camera;
var cam2: Camera;
function Start() {
cam1.enabled = true;
cam2.enabled = false;

}

function Update() {

 if (cam1.enabled == true) {
 cam1.enabled = false;
 cam2.enabled = true;
 }
 else if (cam2.enabled == true) {
 cam1.enabled =true;
 cam2.enabled = false;
 } 
 }

Logic looks fine, but you’ve got it in the Update function, so it will alternate between the two cameras every frame. See this sample code which uses seperate functions to switch back and forth: