Moving the camera with the player

Hi,
I´m hoping someone can show me how to code this or direct me to a tutorial about something similar. Let me see if I can describe this as I see it in my head…
I´m working on a game where the player can move left and right. The game board is roughly twice the size of the viewable area, as the player gets near the right or left sides of the viewable area (red space in the image below) the camera would begin moving (not rotating, moving position) to the right or left to keep the player on screen, as the player got to the edge and could not go any further the camera would have the player on the edge of the screen.

For example - Player begins at zero, they start moving right. When they have 1/4th of a viewable area left the camera starts moving to the left. When the player hits the edge he is completely on the left side of the viewable area. When the player starts going back to the right camera would start moving to the right only when the player gets close, 1/4 screen left, to the viewable area on the left side. Is that understandable?
I hope this image helps…

Thanks

A good place to start would be the unity 2d platformer tutorial:
http://unity3d.com/support/resources/tutorials/2d-gameplay-tutorial.html

This implements most of what you want in terms of a scrolling camera. In order to prevent the camera moving until the player is sufficiently far from the center of the screen, I modified the CameraScrolling.js script (Assets/Scripts/2d/Camera), changing the LateUpdate() function (line 69) to this, and also adding the MaxTrailDistance variable which defines how far the player must move from the centre of the view before the camera moves.

In order for this to work smoothly in the tutorial example, the camera’s springiness variable should be reduced from 4 to 1 - this will reduce the degree to which the camera jumps towards the player once he is far enough away. A nicer way of solving this would be to have the camera move toward the player at a speed dependant on how far away he is, but that’s more than you asked for in your question.

Let me know if you need any more help getting this to work.

var MaxTrailDistance = 4.0; 

// You almost always want camera motion to go inside of LateUpdate (), so that the camera follows
// the target _after_ it has moved.  Otherwise, the camera may lag one frame behind.
function LateUpdate () {
	// Where should our camera be looking right now?
	var goalPosition = GetGoalPosition ();
	
	// Interpolate between the current camera position and the goal position.
	// See the documentation on Vector3.Lerp () for more information.
	if(Vector3.Distance(goalPosition, transform.position) > MaxTrailDistance)
		transform.position = Vector3.Lerp (transform.position, goalPosition, Time.deltaTime * springiness);	
}

Thanks Seregon, I thought I had every tutorial on Unitys website, must´ve missed that one. I´ll go through it tonight.