How to open a gate with a key ?

Hi every one.

I am having problems with assigning key and stuff. So the question is that how do i assign a key to be collected then approach the door and the door opens automatically. Well i already have a script (not animation, because i am having problems with animation) so how do i add the key and unlocking script. Here is my java script to open the gate.

#pragma strict
var AngleX:float = 0.0;
var AngleY:float = 90.0;
var AngleZ:float = 0.0;

private var targetValue : float = 0.0;
private var currentValue : float = 0.0;
private var easing : float = 0.05;

var Target : GameObject;

function Update(){

	currentValue = currentValue + (targetValue - currentValue) *easing; 
	Target.transform.rotation = Quaternion.identity;
	
	Target.transform.Rotate(0, currentValue,0);

}

function OnTriggerEnter (other : Collider){

	targetValue = AngleY;
	currentValue = 0;

}

function OnTriggerExit (other : Collider){

	currentValue = AngleY;
	targetValue = 0.0;

}

OK, this script work with a triggered collider, which means that if you approach a collider which is triggered; the door will open very simple. What i want is that a script with a key so that when i walk to the key it collect my key and the key disappear. (Sorry i am doing to much of ‘key’ ‘key’). My person is 3rd person

Why not store whether the key has been picked up or not by the player in the player’s script. So create a boolean variable like hasKey and set it to true if the key is picked up. The door script can access the hasKey variable from the player, and if the value is true, then the door opens.