Switching between multiple cameras
Choosing from a variety of cameras is a common feature in many genres: racing, sports, tycoon/strategy, and many others. In this recipe, you will learn how to give players the ability to choose from many cameras by using their keyboards.
Getting ready
For this recipe, we have prepared the BasicScene
Unity package containing a scene named BasicScene
. The package is in the 1362_05_codes
folder.
How to do it...
To implement switchable cameras, follow these steps:
Import the
BasicScene
package into a new Project.From the Project view, open the BasicScene level. This is a basic scene featuring an animated character and some extra geometry.
Add two more cameras to the scene through the Create drop-down menu on top of the Hierarchy view (Create | Camera). Rename them
cam1
andcam2
.Change the
cam2
camera's position and rotation so that it won't be identical tocam1
.Create an Empty GameObject by navigating to the Create drop-down menu on top of the Hierarchy view (Create...