Sprite generation

Hi!

I am making an infinite runner game. I have made a very simple script which makes the ground move to the left (making it look like the character is running to the right, when hes actually just running on the spot). When the ground sprite has moved out of the camera view, the character falls of the world (because there is no ground)

I would need some guidance to make my script:

  1. Destroy the ground sprite when it has passed the camera and
  2. Generate the ground sprite at the starting position when it has been destroyed, continiously.

I cant make an infinite runner with a finite amount of ground sprites!

The GroundMovementCode:

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {
	

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		transform.Translate (Vector3.left * 5 * Time.deltaTime); 
	}
}

Thanks in advance and have a nice day!

public float scrollSpeed;
public float tileSizeX;
private Vector3 startPosition;

void Start ()
{
startPosition = transform.position;
}
void Update ()
{
float newPosition = Mathf.Repeat(Time.time*scrollSpeed,tileSizeX);
transform.position = startPosition + Vector3.right*newPosition;
}

Just add this script in your sprite and it will repeat the sprites once it reach the end, So this way you will be looping infinitely. If you have more than one sprite than need to be looped simply create an empty game object and drag the multiple sprites into the empty game object and drop this script in to the parent [empty game object].

Note: Change the scrollspeed and tilesize properties according to your need.