Moving based on static camera view, how to switch second camera as MainCamera

Hi, I have been testing some movement based on static camera, having player move based on camera view.
Imagine it as classic resident evil game without tank controls. My problem is, when hitting trigger to cam2, the movement implemented by camera view is still working from cam1.
I have this:

if (cam == null)
{
cam = Camera.main;
}

which tracks MainCamera.
I am kinda new to unity and c#, I am trying to find way to toggle the MainCamera tag on trigger between active cameras. Thanks

In order to change to a different camera, you need to enable one and disable the other:

public Camera cam1, cam2; //assign these in the inspector
void Update() {
if (Input.GetKey(Keycode.F) ) {
cam1.enabled = true;
cam2.enabled = false;
}
else {
cam1.enabled = false;
cam2.enabled = true;
}
}

But this isn’t very extensible, especially if you’re doing Resident Evil and will have hundreds of cameras throughout the level. If you try to make this work on that scale, you’ll likely end up with bugs where a bunch of cameras render on top of each other (but you only see 1), causing slowdown.

A better approach for a RE type game is to have just one camera, but you move it to match some specified object’s position. You could do this on a trigger collision on a different object, so if the player enters this room-shaped collider, it sets the camera position to this other object’s position:

public class TriggerCameraMover : MonoBehaviour {
public Transform dummyCamera;
void OnTriggerEnter(Collider c) {
if (c.gameObject.tag == "Player") { //or any "is this the player" condition
Camera.main.transform.position = dummyCamera.position;
Camera.main.transform.rotation = dummyCamera.rotation;
}
}

Put this script on the object with the trigger collider and assign your dummy camera. Now you can have a thousand of these and they won’t interfere with each other or anything, and the only performance overhead will be the cost of the trigger colliders themselves.