Time for action – improving the camera
Right now, our camera always stays in the same place. This confines our game to a very small area. To extend this area a little bit, we'll use one simple line of code that will keep the camera trained on our marble constantly. Perform the following steps to expand the viewing area of the camera:
Create a new C# script called
TrackingCamera
in yourScripts
folder and open it up.Add the following variable to the script above the
Start
function:public GameObject objectToTrack; void Start () { }
The
public
keyword before theGameObject
variable type makes the variable accessible to the Unity editor and other scripts. We'll use this accessibility to our advantage and tell the script to track the marble right in the editor without any additional code.Save the script and left-click and drag it onto the Main Camera object in your Hierarchy menu.
In the new script pane on the camera's list of components, a slot for your public variable will appear just below...