Game Development Reference
In-Depth Information
// Distance in the y axis the player can move before the
// camera follows.
public float yMargin = 1.5f;
// How smoothly the camera catches up with its target
// movement in the x axis.
public float xSmooth = 1.5f;
// How smoothly the camera catches up with its target
// movement in the y axis.
public float ySmooth = 1.5f;
// The maximum x and y coordinates the camera can have.
public Vector2 maxXAndY;
// The minimum x and y coordinates the camera can have.
public Vector2 minXAndY;
// Reference to the player's transform.
public Transform player;
}
The variables are all commented to explain their purpose, but we'll cover each as we use
them.
First off, we need to get the player object's position so that we can track the camera to it
by discovering it from the object it is attached to. This is done by adding the following
code in the Awake function:
void Awake()
{
// Setting up the reference.
player = GameObject.Find("Player").transform;
if (player == null)
{
Debug.LogError("Player object not found");
}
Search WWH ::




Custom Search