Destroying Old Objects Only by thier names?

Destroying All of the Objects with a specific name and with z axis less than the player!!

Hi I’m creating a game with highscore and i was trying to destroy old objects because i dont want to kill the memorey!

so i said let’s Destroy Objects Which Cant Be Seen Anymore and also they are not usefull any more so i used GameObject.Find function but it is working with a good Delay!!!
Also It’s Working Only Once !

i think this is not a good function For this situation but i dont know how to use other simillar functions :confused: Can AnyOne Help Me Destroying All of the Objects with a specific name and with z axis less than the player!!

This is What I’ve used and it has the delay problem and also After Destroying the variable it gets and error so the problem might be because of that thing too but how can i destroy an object without destroying it’s variable!!

var Player:Transform;
function Update () {
var Pipe = GameObject.Find("concretePipe");
if(Pipe.transform.position.z + 10< Player.position.z) 
{
Destroy(Pipe.gameObject);
print("Deleted");
}
}

function KillThemAllWithTheSameTagAndWithZLessThanPlayer(){
var allOfThem:GameObject;//decalre an array
allOfThem = GameObject.FindGameObjectsWithTag(“TagOfObject”);//find them all
for(var obj:GameObject in allOfThem){//iterate through the array
if(obj.transform.position.z<transform.position.z)Destroy(obj);//compare and destroy
}
}
And you call it like this:

function Update(){
   if(Input.GetKeyDown(KeyCode.A))KillThemAllWithTheSameTagAndWithZLessThanPlayer();
}

This is attached to the player.
Remember that the convention for function names is to start with a cap letter and to be descriptive of what they do.