As we are creating an endless runner, we need our environment to seamlessly repeat infinitely. There are various ways to do this; however, with the new Unity 2D animation, we can simply use the 2D animation to accomplish this by animating the background moving.
To do so, we need to do the following:
Add a folder named
Background
toAssets
within the Project Browser.Download and unzip the
desert_BG.png
image from http://freeartsprites.com/free-art/endless-runner/.Create a sprite GameObject using the following image:
Make a duplicate of the image by pressing Crtl + D, and position it on the right-hand side so that they are seamless.
Change the camera aspect ratio to 16:9.
Ensure that the left-hand side
desert_BG
object fits perfectly within the camera view.Drag the right-hand side
desert_BG
object in the hierarchy onto the left-hand sidedesert_BG
object so that the left-hand side object is the parent.Now, select the left-hand side object, and open the Animation View:
Go to Window...