Switching Cameras in Unity.
In this guide I just want to quickly go over a simple way to switch between cameras in Unity. We can achieve this by setting different cameras on or off using SetActive().
We first start by deciding on the condition we use to change the camera. For now we’ll use Input buttons 1, 2 and 3 to switch between cameras. We go into Project Settings -> Input Manager and add three new items to the list, which we’ll label Switch1, Switch2, and Switch3. Each correspond to the button on the keyboard.
Then we write a C# script called CamSwitch. All we need is three public GameObjects which we’ll label cam1, cam2, and cam3 for each of the cameras we’ll be switching into. Inside the Update function, depending on which button we press, we’ll turn the corresponding camera active while setting the other cameras false.
We then need to create two additional camera on the Scene and place them where we want it to. Only set the camera you want the players to see first active and the other camera inactive.
Last we create an empty GameObject called CamManager to store the script, and link the cameras to the script.
With this when we click on play, and press 1, 2, or 3, we’ll switch between the different camera and see from a different angle.