Moving game objects to simulate infinite background

The idea is that I have a stack of background and ground tiles that are behind the player on a side scroll. As the players travels to the right there is a object (BCcollector) that is suppose to contact the background tiles and relocates it behind the furthest one to the right so it appears to be infinite. Here is the code that I’ve put together. I’m VERY new to coding so its hard for me to grasp sometimes. I know making the player stand still and having the background is more efficient and easier but I wanted to try it with the player moving. Any help and advice would be greatly appreciated.

The background tiles are tagged as background and they all have colliders

The object that collides with the tiles has a box collider that is set to be a trigger and moves just off screen and is attached to the camera which follows the player.

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

public class BGCollector : MonoBehaviour {
private GameObject[ ] backgrounds;
private GameObject[ ] grounds;

private float lastBGX;
private float lastGroundX;

// Use this for initialization
void Awake () {
backgrounds = GameObject.FindGameObjectsWithTag(“Background”);
grounds = GameObject.FindGameObjectsWithTag(“Ground”);

lastBGX = backgrounds[0].transform.position.x;
lastGroundX= grounds[0].transform.position.x;
//locates last background tile
for(int i = 1; i < backgrounds.Length; i++)
{
if(lastBGX < backgrounds*.transform.position.x)*
{
lastBGX = backgrounds*.transform.position.x;*
}
}
//locates last tile in line
for (int i = 1; i < grounds.Length; i++)
{
if (lastGroundX < grounds*.transform.position.x)*
{
lastGroundX = grounds*.transform.position.x;*
}
}
}

//relocates tile collided and moves to end of line
void OnTriggerEnter2D (Collider2D target) {
if (target.tag == “Background”)
{
Vector3 temp = target.transform.position;
float width = ((BoxCollider2D)target).size.x;
temp.x = lastBGX + width;
target.transform.position = temp;
lastBGX = temp.x;
}
else if(target.tag == “Ground”)
{
Vector3 temp = target.transform.position;
float width = ((BoxCollider2D)target).size.x;
temp.x = lastGroundX + width;
target.transform.position = temp;
lastGroundX = temp.x;
}
}
}

Use this:

Don’t use this:

GameObject.FindGameObjectsWithTag

Other than that, yea I’d make the player stay still and move the background instead.