Question by
Alphacreations · Apr 14, 2020 at 02:31 PM ·
backgroundrepeat
,Parallax background not loading fast enough
I am trying to implement a parallax background in my game and the background repeats the children after my camera has passed the position. Like in a working parallax background, the children always surround the camera but in my parallax background, the children are either both behind the camera or both in front of the camera
my script is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Parralax : MonoBehaviour
{
private float length, startpos;
public GameObject cam;
public float parralaxeffect;
void Start()
{
startpos = transform.position.x;
length = GetComponent<SpriteRenderer>().bounds.size.x;
}
// Update is called once per frame
void Update()
{
float temp = (cam.transform.position.x * (1 - parralaxeffect));
float dist = (cam.transform.position.x * parralaxeffect);
transform.position = new Vector3(startpos + dist, transform.position.y, transform.position.z);
if (temp > startpos + length) startpos += length;
else if (temp < startpos - length) startpos -= length;
}
}
could someone please help me
Comment