2d Endless Runner: Deleting objects behind player and platform limit

I am making a 2d endless running game. I currently have a platform generating script with the
following Update function:

 function Update () {
    if(platformCount!=platformCount-recycle.stdest){
    platformCount-=recycle.stdest;
    }
    if (locked==false &&platformCount<=platformCap){
    Generate();

and a script deleting previous platforms:

 #pragma strict
    var objToCheck: GameObject;
    var distance:float;
    var destroyed:int;
    static var stdest:int;

function Update () {
objToCheck=GameObject.FindWithTag ("platform");
 distance = Vector3.Distance(objToCheck.transform.position, transform.position);
 if (distance>100){
 Destroy(objToCheck);
 destroyed++;
 stdest=destroyed;
 }
}
        }

It is designed to only have 30 platforms at a time, to reduce any lag. It works fine until the first platform gets deleted, then the cap becomes useless and infinite platforms are generated. Does anyone have an idea of what is going on?

EDIT: I just realized what i did(a number minus another number will never equal itself unless the number is 0) but im not sure how i should go about properly using my scripts to keep the number of platforms at 30.

GameObject.FindWithTag() will return a single object, it will return the first one it finds using it’s internal algorithm, as far as we are concerned it could be any of them.

You will need to iterate though the collection returned by GameObject.FindGameObjectsWithTag() if you want to apply you logic to all of the platforms.

You may find that your record keeping could be simplified by using GameObject.FindGameObjectsWithTag().Length

Hello I know this thread is an old one… but ive got the same problem. Can you give me the codes that you created that you figured out… im a clutz at creating array.