Making A 2d game android

hello to all,
I’m trying to make a game like this:

a 2d game in which the character runs endlessly.
But I do not know how to make this thing of '“infinity.”
I realize the potential of prefab obstacles along the ground, and instantiate them in code, but I realized that it is terribly heavy, and I always stops to load the route.
Do you have any advice for me?
thanks in advance

var cube : GameObject;
var position = Vector3(x,y,z);

InvokeRepeating(SpawnCube, 0.0, 2);

function SpawnCubes () {
		Instantiate(cube, position, Quaternion.identity);

this will spawn a cube every 2 seconds at the position you enter in position variable.
when I was working on same kind of game I destroy cubes when they were on colision with game object on left side out of camera view. this game object was chid to pplayer, so it stayed on same positon when the player was destroy cubes check this link
and this one