// Update is called once per frame void Update() { //Check if Swapped area if (player.transform.position.x > currentArea.rightExtent()) { //Check if need to loop if (currentAreaIndex == areas.Count - 2) { //Move the first area to the last spot in list areas.Add(areas[0]); areas.RemoveAt(0); //Update currentArea reference currentArea = areas[currentAreaIndex]; //Move the area in World Space position.x = currentArea.rightExtent() + (areas[areas.Count - 1].getWidth() / 2.0f); areas[areas.Count - 1].transform.position = position; } else { //Update current area currentAreaIndex++; currentArea = areas[currentAreaIndex]; } } else if (player.transform.position.x < currentArea.leftExtent()) { //Check if need to loop if (currentAreaIndex == 1) { //Move the first area to the last spot in list areas.Insert(0, areas[areas.Count - 1]); areas.RemoveAt(areas.Count - 1); //Update currentArea reference currentArea = areas[currentAreaIndex]; //Move the area in World Space position.x = currentArea.leftExtent() - (areas[0].getWidth() / 2.0f); areas[0].transform.position = position; } else { //Update current area currentAreaIndex--; currentArea = areas[currentAreaIndex]; } } }