How do I pick up an item off of a key down click?

I’m making a game that requires you to pick up a puzzle piece and I am having trouble making it so it picks up off a key click. Help please :slight_smile:

var size : Vector2 = new Vector2(400,100);	// Setting size of box
var hand : Transform;	// give the object inthe hierarchy a variable
var cube : Transform;
var hitbox : GameObject;
var tripwire = false; // variable is used for telling if the character is in or out of the collider

function Start () // Program will find the objects no matter where they are at or in what program
{

}

function Update () 
{
}

function OnGUI () //Builds the Box with the message to pickup item using the tripwire variable
{
	if (tripwire == true)
	{
		GUI.Box(Rect (200,275, size.x, size.y), "Press E to pick up the puzzle piece!");
	}		
}

function OnTriggerEnter (col : Collider) // decides if player is in the box or not and displays message and gives the option to pick  the item
{
	if (col.gameObject.name == "Player")
	{
		if(Input.GetButtonDown (KeyCode.E))
		{
			transform.parent = hand.transform;
   			transform.position = hand.transform.position;
   		}
		tripwire = true;
	}
}

function OnTriggerExit (col : Collider) // removes box from screen and opton to pick up item
{
	if (col.gameObject.name == "Player")
	{
		tripwire = false;
	}
}

Try the OnMouseUpAsButton() function.