Hi guys, so I’m essentially trying to create a kind of infinite runner, and part of it for me is to spawn just a block continuously, with random spacings apart.
Of course, this will get laggy, so I delete them after a while.
I put the following script on a block, save it as a prefab, and add the prefab as the Obj
#pragma strict
var Obj : GameObject;
function Start () {
var RanDistance = Random.Range(8,21);
var Dist = transform.position;
Dist.z += RanDistance;
yield WaitForSeconds (0.2);
Instantiate(Obj, Dist, transform.rotation);
yield WaitForSeconds (10);
Destroy (gameObject);
}
function Update () {
}
This works, however, eventually, the deleting catches up too much with the spawning, and increasing the wait time before deleting only delays the time until that happens. Any fix for what I want to do?