Time for action – setting up two additional cameras in the scene
We'll have three cameras, but only one will be active at a time. Their names are:
- Main Camera
- LookAt Camera
- Following Camera
Do the following steps with Scene0 loaded to add two cameras:
- Add a Camera GameObject and name it
LookAt Camera
. - Set its Transform Position to
50
,7
,50
. - Uncheck its Active checkbox.
- Add a Camera GameObject and name it
Following Camera
. - Uncheck its Active checkbox.
- Drag both of these cameras onto GameManager to make them children.
Look in the Scripting Reference for GameObject.SetActive. It's a method to set whether a GameObject is active or not. However, Unity can't find an inactive GameObject using the
GameObject.Find()
method. So we'll store a reference to each camera in a List.
Line 10 in the following screenshot of the GameData
script creates the List to store the three cameras:
Now we'll add all the cameras in Scene0 to the List:
- Select GameManager in the Hierarchy panel.
- In the...