Generating a smooth stream of objects

I’m attempting to make an endless flier game (you have a ship and it flies toward the right side of the screen forever, navigating obstacles along the way).

I want a smooth floor/ceiling along the bottom/top of my game window, and I’d hoped to accomplish this by generating a steady stream of 1 unit by 1 unit cubes, textured such that each row of cubes appears to be a single seamless wall. The floor and ceiling cubes move to the left, giving the illusion the player’s shit is flying past them.

However, there are tiny gaps in-between the cubes, ruining the effect I’m going for. The cubes each move at speed of 5, using the code below:

function Update () {
	transform.Translate(Vector3(moveSpeed * Time.deltaTime * -1, 0, 0));
}

I have a timer generating each cube, using a frequency of 0.2 and the code below:

function updateWallTimer(){
	wallTimer -= Time.deltaTime;
	if(wallTimer < 0)
	{
		spawnWall();		
		wallTimer = 0.2;
	}
}

function spawnWall(){
     var floorPos : Vector3 = Vector3(10, 0, 10);
     var floor = Instantiate(wallBlock, floorPos, Quaternion.identity);
}

As I understand it, the movement speed of 5 multiplied by the frequency of 0.2 gives a result of 1, which should place the 1x1 cubes side-by-side. However, it appears that Time.deltaTime isn’t precise enough, causing small gaps to appear between the cubes.

Would I be better off using Time.time? Is there another, easier way to achieve the effect I’m looking for? Any help would be greatly appreciated!

I will use C#:

void Start()
{
    StartCoroutine(spawnWalls());
}

IEnumerator spawnWalls()
{
    int x=0;
    while(true)
    {
        GameObject floor = (GameObject) Instantiate(wallBlock, new Vector3(x,0,10),Quaternion.identity);
        yield return new WaitForSeconds(0.2f);
    }
}

Aha! I had no idea coroutines were a thing.

Let me mess around with this for a bit, and I’ll post my results.

EDIT: While the coroutine is certainly a cleaner way to do things, I’m still running into the same issues as before (there are tiny gaps between each of the wall chunks).

However, I did have some luck using a coroutine fired on wallBlock instantiation that generates another wallBlock 1 unit to the right of the current wallBlock, after a 0.2 second delay. The new wallBlock initiates this coroutine on itself, intantiating another wallBlock, and the cycle continues indefinitely.

Thank you for your help!

or you could have your player and floor / ceiling not move at all and have the background / obstacles move right to left across the screen. player then just has the power to move up and down to avoid them while appearing to constantly move forward. ceiling and floor are one solid object each so no gaps and no need to update them / create them.

I considered that, but I want the ceiling and floor to have a continuously increasing chance of generating a ceiling/floor 2 blocks high, then 3, the 4, etc. up to whatever threshold I declare to be the ‘hardest’ difficulty.

In order to have that work, the ceiling/floor needs to constantly generate and destroy itself once outside the screen.

I would have a prespawned set of wall objects and check if they have gone past the edge of the screen.
I’d then move them back with the width of the wall, that way they keep the original spacing.