# Destroy a single list member

im trying to destroy a single game object using the following script but it destroys all of them , not the ones I want. I want to destroy the ones that the transform that holds this script collides with.

It's a 2D unity3d game btw.

The script :

var keys : List.<Transform>;

function OnTriggerEnter2D(coll : Collider2D)
{
for(var i = 0; i < keys.Count; i++)
{
Destroy (keys[i].gameObject);
}
}


I hope I was clear enough , don't hesitate to ask any questions.

Thank you for your time.

## 1 Answer

I fixed this by editing my code into this :

function OnTriggerEnter2D(coll : Collider2D)
{
if(coll.gameObject.tag == "Key")
{
Destroy (coll.gameObject);
keysGathered ++;
}
}


I didn't realise it was this simple.

Thank you for your time!