Game Development Reference
In-Depth Information
There is a bunch of new things in this script that need to be discussed in detail. First of
them is the variable called
playerCharacter
which has the type
Transform
. Until now we have
been using variables that store numbers, and were able to use input fields in the inspector to
set their values using the keyboard.
Due to the nature of this script, it is required to deal with more than one object. On one
hand, we attach this script to the camera to control its movement. And, on the other hand,
the script needs to deal with the character; in order to update the position of the camera
according to the position of the character. That's why we have defined
playerCharacter
variable, which is going to be used to reference the object of the character, specifically the
Transform
component of that object. We need now is to bind this variable to the character
object, so that the script knows the position of the character when the game runs. Illustra-
tion 19 shows how to bind a game object from the scene to a variable in a script.