Hi everyone, i'm developing a 2D game in which i want to add a background that scrolls down in an infinite way, as time passes. How can i do it? Thank you very much !
The easiest way to do this is to have 2 identical background objects, let's say one at (0,0,0) and one at (0,10,0) (have them line up edge to edge; I'm going to assume for this that they are 10 units tall). Put these both under a single parent object. Now, something like this on the parent: (C#) Code (csharp): public float moveSpeed = 2f; public float loopMax = 10f; public float loopMin = 0f; void Update() { transform.position += new Vector3(0f, moveSpeed * Time.deltaTime, 0f); if (transform.position.y > loopMax) { transform.position += new Vector3 (0f, loopMin - loopMax, 0f); } } This moves the object upwards until its Y reaches loopMax, at which point it moves it down to loopMin - well, almost to loopMin. This will actually result in a smoother animation than going to loopMin, because it doesn't discard the little fractions of a unit that the background moves in a frame.
another way that you can do it is by creating a tall atlas file containing the images.. just like a movie is.. img1 img2 img3 img4 but to make it loop seamless, you simply add the first frame at the end again... img1 img2 img3 img4 img1 the image 4 must to be coherent with 1. add an animation to it to pass from frame1 (top) to frame1 (bottom)... and set wrap mode to loop..
An alternative approach would be to have the background move with the camera and just pan the UVs in the desired direction.