What I would do as dannyskim said is move the transform position of the camera to the character. So On a script that is attached to the player add this:
void Start () {
mainCamera = (GameObject) GameObject.FindWithTag ("MainCamera");
}
void Update () {
mainCamera.transform.position = new Vector3(transform.position.x,10,transform.position.z);
}
And then on a script attached to the main camera add:
transform.position = new Vector3(Mathf.Clamp(transform.position.x, leftLimit, rightLimit), transform.position.y, transform.position.z);
In the Update somewhere, where left limit and right limit are public floats you have defined at the top of the script.
Note that this is done in C# but is very easily converted to Unity Script, if you look at the documentation.
Peace,
↧