How to make a "Pick Up" script?

I would like to have a script that will be able to obviously pick up objects that are able to. More specifically, how can I pull off a paper note or letter. When you click ‘e’ on a object, a ‘paper note’ gui will appear on the screen, until the player closes it. How can I do this, and how can I do this neatly and efficiently? It’s inspired by the game “Amnesia: The Dark Descent”.

For this you will have to use:

*Raycasting, for getting what are you looking at.

*Create some item structure, so player would know what item is what, item logo etc.

*Getcomponent in runtime to access object you want to pick up

*Create tags for pickable objects

*Other stuff, questions which will come by learning and trying to script things

Put this script onto your player object or camera:

var Letter : GameObject;//leave empty, the script will assign it
var Image : Texture2D;//leave empty, the script will assign it
var ShowLetter : boolean;//don't touch :)
var LetterMask : LayerMask;//select the layer of your letter object in this drop-down list
var cam : Transform = Camera.main.transform;

function Update()
{
	var ray = Ray(cam.position, cam.forward);
	var hit : RaycastHit;//stores information about things we hit with our raycast
	
	if(Input.GetKeyDown(KeyCode.E))
	{
		if(ShowLetter == false)
		{
			if (Physics.Raycast (ray, hit, Mathf.Infinity, LetterMask))
			{
				Letter = hit.collider.gameObject;//assigns the letter object that was hit by the raycast to this script's Letter variable so we can access it, should we want to pick it up.
				Image = hit.collider.gameObject.GetComponent(LetterScript).LetterImage;//assign the LetterImage from the letter object that was hit to this script's Image variable so it can be accessed in OnGUI()
				ShowLetter = true;
			}
		}
		else
		{
			ShowLetter = false;//if the letter image is already being shown, hide it again.
			//here, you could also make the player pick up the letter object by making it a child of himself:
			if(Letter != null)//just to be sure, check if the Letter variable isn't empty
			{
				Letter.transform.parent = transform;//make the letter a child of the player so it stays with him. It's not really needed though.
				Letter.transform.position = transform.position;//put the letter at our player's location.
				Letter.renderer.enabled = false;//make to Letter object invisible, we don'T want to see it while carrying it, right?
				Letter.collider.enabled = false;//disable the Letter object's collider, so it doesn't interfere with any raycasting we do.
			}
		}
	}
}

function OnGUI()
{
	if(ShowLetter == true)
	{
		GUI.DrawTexture (Rect (Screen.width / 2 - Image.width / 2, Screen.height / 2 - Image.height / 2, Image.width, Image.height), Image);
	}

}

And this mini script, called LetterScript, has to be attached to your letter gameobject:
(be sure to drag an imaage to the LetterImage variable!)

var LetterImage : Texture2D;