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
This recipe adds to the scene created in the first recipe of this chapter, so make a copy of that project folder and do your work for this recipe with that copy.
How to do it...
To implement switchable cameras, follow these steps:
- Create a new
Camera
in the Scene namedCamera-1
(Create
|Camera
). Set its position to (0,0,0
). Set theTag
for thisCamera
to be MainCamera. - Duplicate
Camera-1
, naming the copyCamera-2
. Set itsPosition
to (0, 0, -15
), and itsRotation
to (20, 0, 0
). - Disable the
Camera
andAudioListener
components for bothCamera-1
andCamera-2
. - Create an empty
GameObject
named switchboard (Create
|Create Empty
). - Create a new C# script-class named
CameraSwitch
containing the following, and add an object...