Initial commit
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user