camera follow up the object

i have a script which is working fine while pressing the arrow keys.now i want the camera to follow the object

var speed : float = 6.0; var jumpSpeed : float = 8.0; var gravity : float = 20.0;

private var moveDirection : Vector3 = Vector3.zero;

function Update() { var controller : CharacterController = GetComponent(CharacterController); if (controller.isGrounded) { // We are grounded, so recalculate // move direction directly from axes moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed;

    if (Input.GetButton ("Jump")) {
        moveDirection.y = jumpSpeed;
    }
}
 
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
 
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}

If you want the camera to follow, one options is to put the camera at the position that you want. And make it a child of the Player. (Just drag the MainCamera into the player at hierarchy). Hope it helped. Take Care.