Scrolling repeating ground

Hi, I have a side scrolling shooter.

The level should just go on forever, until player dies. I just want to create a ground for the level.
Same flat ground that just keeps repeating over and over.

Does anyone know the best way to do this. I created a ground image, gave it velocity and set it to respawn every few seconds, killing the old one, but it just seems to lag my game.

For better performance simply move the last piece to the front once it is off screen. The code sample below is one way to do it. This gets attached to each GameObject you want to cycle through. I built this one for four 1024*1024 images. Adjust the numbers on reset to match your needs.

public class BackDropScroll : MonoBehaviour {

	private Vector3 reset;

	void Start () {
		reset = Vector3.right * 4 * 10.24f;
	}
	
 	void Update () {
		Vector3 Trans = Vector3.left * Time.deltaTime;
		transform.Translate (Trans);

		if (transform.position.x < -20) {
			transform.Translate (reset);
		}

	}
}

Other thoughts

Respawn is expensive. Destroying the old one will lead to garbage collector overheads, instantiate is not cheap either.

I would also suggest moving the transform directly instead of giving it velocity. That way it won’t cause any strange effects when colliding.

You could leave the ground in place and, instead, move the texture on it according to the player speed by scrolling the UV’s using something like this: http://wiki.unity3d.com/index.php?title=Scrolling_UVs.

Hope this helps!