Scrolling Repeating Backgrounds

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TileManager : MonoBehaviour {

public GameObject[] tilePrefabs;
private Transform playerTransform;
private float spawnY = 3.0f;
private float tileLength = 18.0f;
private float safeZone = 20.0f;
private int amnTilesOnScreen = 3;
private int lastPrefabIndex = 0;
private List<GameObject> activeTiles;


void Start () 
{
activeTiles = new List<GameObject>();
playerTransform = GameObject.FindGameObjectWithTag ("Player").transform;
for (int i = 0 ; i < amnTilesOnScreen; i++)
{
SpawnTile ();
}
}

void Update () 
{
if(playerTransform.position.y - safeZone > (spawnY - amnTilesOnScreen * tileLength))
{
SpawnTile();
DeleteTile ();
}
}

private void SpawnTile(int prefabIndex = -1)
{
GameObject go;
go = Instantiate(tilePrefabs[RandomPrefabIndex()]) as GameObject;
go.transform.SetParent(transform);
go.transform.position = Vector3.up * spawnY;
spawnY += tileLength;
activeTiles.Add (go);
}

private void DeleteTile ()
{
Destroy (activeTiles [0]);
activeTiles.RemoveAt (0);
}

private int RandomPrefabIndex()
{
if (tilePrefabs.Length <= 1)
return 0;
int randomIdex = lastPrefabIndex;
while (randomIdex == lastPrefabIndex)
{
randomIdex = Random.Range (0,tilePrefabs.Length);
}	
lastPrefabIndex = randomIdex;
return randomIdex;
}

}
Ask or Request for anything you want in the comments below 😀