32 lines
891 B
C#
32 lines
891 B
C#
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<PlayerController>();
|
|
startPos = transform.position;
|
|
repeatWidth = GetComponent<BoxCollider>().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;
|
|
}
|
|
}
|
|
}
|