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.