Camera toggle and position

Hi
I have 2 cameras and a script that switches between the cameras using ‘q’ and ‘e’.
But I want that RMB toggles between camera 1 and 2. I don’t want to use 2 buttons.

I also need to fix that the rotation positions of the cameras are synced.
because right now, when camera1 is looking up and I switch to camera2, camera2 is still looking straight forward.

This is my javascript:
var camera1 : Camera;
var camera2 : Camera;
var sound1: AudioClip;
var sound2: AudioClip;

function Start () {
 
camera1.camera.active = true;
camera2.camera.active = false;
 
 
}
 
 
function Update () {
 
if(Input.GetKeyDown("q")) {
 
camera1.camera.active = false;
 
camera2.camera.active = true;

audio.PlayOneShot(sound1);
 
}
 
 
 
if(Input.GetKeyDown("e")) {

camera2.camera.active = false;
 
camera1.camera.active = true;

audio.PlayOneShot(sound2);
 
}
 
 
}

For the first part use this

   #pragma strict
    var camera1 : GameObject;
    var camera2 : GameObject;
    
    function Start () {
    	SwitchCameras();
    }

    function Update () {
    //right mouse button
        if(Input.GetMouseButtonDown(1)) {
           SwitchCameras();
           PlayAudio();
        }
   }
    function SwitchCameras(){
    	if(camera1.camera.active == true){
    	    camera1.camera.active = false;
    	    camera2.camera.active = true;
    	}
    	else {
    	    camera1.camera.active = true;
    	    camera2.camera.active = false;
    	}
    }
    
    function PlayAudio(){
    	if(camera1.camera.active == true){
    	    audio.PlayOneShot(sound1);
    	}
    	else if (camera2.camera.active == true){
    	    audio.PlayOneShot(sound2);
    	}
    }

You have to drag your two cameras there.

Assign a target to the cameras (I assume you want to be looking at player) so they can look at the same point when switched, if they don’t have the same point then the other camera have infinite points to look at and those lay on the direction line the first camera is facing.

Drag this on each camera and drag player as target.

#pragma strict
var target : Transform;

function Update () {
	transform.LookAt(target);
}

Radivarig