using UnityEngine;

public class Parallax : MonoBehaviour {

    public GameObject cam;
    public float parallax;
    private float startPos;
    private float length;

    void Start() {
        startPos = transform.position.x;
        length = this.GetComponent<SpriteRenderer>().bounds.size.x;
    }

    void Update() {
        float distance = cam.transform.position.x * parallax;
        transform.position = new Vector3(startPos + distance, transform.position.y, transform.position.z);
        float temp = cam.transform.position.x * (1 - parallax);

        if (temp > startPos + length) {
            startPos += length;
        }
    }
}
