Hello everyone! I’m trying to create a repeating background but it don’t work… can you help me please?
These is my code for repeating the background:
3219066–246671–Ripetizione.cs (698 Bytes)
Hello everyone! I’m trying to create a repeating background but it don’t work… can you help me please?
These is my code for repeating the background:
3219066–246671–Ripetizione.cs (698 Bytes)
Here’s how i did it in a space game I was working on
public class StarMovement : MonoBehaviour {
private float movementDelay = .4f;
private float time;
private SpriteRenderer stars;
private float camheight;
private float camwidth;
public GameObject nextStars;
void Start () {
time = Time.time;
Camera cam = Camera.main;
camheight = 2f * cam.orthographicSize;
stars = GetComponent<SpriteRenderer> ();
}
void Update () {
if (Time.time > time + movementDelay)
{
if (transform.position.y == 0) {
Instantiate (nextStars,new Vector2 (transform.position.x, camheight*2), Quaternion.identity);
}
if ((transform.position.y + (stars.bounds.extents.y*2)) > 0)
{
transform.position = new Vector3 (transform.position.x, transform.position.y - 1);
} else {
Destroy(gameObject);
}
time = Time.time;
}
}
}
Nowadays I would probably just have two background objects in a single parent object and swap between them as they scroll.
Thanks =)