The Last of the Bunnehs avaible on Google Play!!
public class Parallax : MonoBehaviour //I had this from previous games, copy in the description to the video
{
public Transform[] backgrounds;
private float[] parallaxscale; //how strong paralax
public float smoothing = 1f;
private Transform player;
private Vector3 previousPos;
void Awake()
{
player = GameObject.FindGameObjectWithTag("Player").transform;
}
void Start()
{
previousPos = player.position;
parallaxscale = new float[backgrounds.Length];
for (int i = 0; i < backgrounds.Length; i++) { parallaxscale[i] = backgrounds[i].position.z * -1; }
}
void Update()
{
for (int i = 0; i < backgrounds.Length; i++)
{
float parallax = (previousPos.x - player.position.x) * parallaxscale[i];
float backgrounsTargetPosX = backgrounds[i].position.x + parallax;
Vector3 backgroundTargetPos = new Vector3(backgrounsTargetPosX, backgrounds[i].position.y, backgrounds[i].position.z);
backgrounds[i].position = Vector3.Lerp(backgrounds[i].position, backgroundTargetPos, smoothing * Time.deltaTime);
}
previousPos = player.position;
}
}