using UnityEngine; public class RepeatBackground : MonoBehaviour { private float backgroundSpeed = 50; private Vector3 startPos; private float repeatWidth; private PlayerController playerControllerScript; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { playerControllerScript = GameObject.Find("Player").GetComponent(); startPos = transform.position; repeatWidth = GetComponent().size.x / 2; } // Update is called once per frame void Update() { if (!playerControllerScript.gameOver) { transform.Translate(Vector3.left * backgroundSpeed * Time.deltaTime); } if (transform.position.x < startPos.x - repeatWidth) { transform.position = startPos; } } }