The camera has an enabled
property, by changing which you can turn the camera on or off. It remains only to apply this knowledge in the script.
If through the UI, then the buttons can assign an OnClick
event.
Add two buttons:

In their properties we find OnClick
.

In it, you need to select the object on which the script handler hangs, and then in the right part of this handler select the same method that will be processed.

Everything. Is done.
The script itself looks like this:
using UnityEngine; public class SwitchCameras : MonoBehaviour { public Camera cam1; public Camera cam2; private void Start() { cam1.enabled = true; cam2.enabled = false; } public void Switch() { cam1.enabled = !cam1.enabled; cam2.enabled = !cam2.enabled; } }
Where cam1
and cam2
assigned to cam1 and cam2 respectively. And where each of the cameras changes the enabled
property to the opposite of what it had.
It is also possible to deal with cameras as normal objects, which can be made active or inactive via SetActive
that is, to turn on the camera you will need to write something like
cam1.gameObject.SetActive(true);
For example, in the same script we can define a method with the parameter
public void Switch(int numCameraToOn)
which will accept the number of the camera to be turned on. The rest - turn off.
When a method with arguments appears - in the button's OnClick
event, you can add this parameter:

for one button, the argument is put for example the number 1, the other button - 2.
When one of the buttons is pressed, we turn on one camera, turn off the other through SetActive