In this section we will look at the CameraRig component that controls the way in which the camera moves. In later sections we will focus on the UI and input components attached to the GameCamera object.
Adding the Template camera
The Unity Tower defense Template comes with a predefined camera already set up to use in Tower Defense games.
Delete the default camera from the scene Hierarchy window
Drag the GameCamera prefab from Prefabs/Player/ into the Hierarchy
Understanding the CameraRig component
The GameCamera GameObject has a component called CameraRig, which provides us with a number of ways to adjust how the camera works:
Look and Movement Damp Factors
These two fields control how springy the camera movement will be. The higher this is, the smoother the camera motion will be.
Nearest Zoom, Furthest Zoom, Max Zoom
These fields control the zoom extents of the camera.
Max Zoom is only relevant if Springy Zoom is checked on below. It controls how much further than the Furthest Zoom the player is able to zoom out before zoom is clamped entirely.
Zoom Log Factor
Only relevant if Springy Zoom is checked on below. Determines how "strong" the rubber band effect is.
Zoom Recover Factor
Only relevant if Springy Zoom is checked on below. Determines how quickly the zoom returns to its normal maximum extents after the player releases.
This camera assumes the ground is at a fixed Y level, and this value sets where that plane is in the world.
Zoomed Cam Angle
A reference to a transform that has the camera’s angle when fully zoomed in.
Whether zoom rubber bands at the near and far zoom points.
When the CameraRig is selected, a rectangular area will appear in the scene view with draggable handles at its edges. The camera cannot move outside of this rectangle. We can use the handles to make this area bigger or smaller.