Create a Scrolling Background in Unity

Mike Brisson
3 min readMar 26, 2021

--

One of the more convincing methods to perceiving motion is to have a background that is moving. It’s a trick that’s been used for ages and now you’ll be able to use it too.

First up, create a quad and scale it to the size of your scene:

Next up, you need to import an image into your project that you want as your background. You can Google the type of background image you want if you don’t already have one.

Ideally, you want an image that’s set to tile or one with no overlap along the scroll axis like this one:

This one is from https://www.freepik.com/

After importing the image into your project, you will want to create a new material with your new asset by dragging the image into the “Base Map”:

In older versions of Unity, Base Map is named “Albedo”

Create a new script and add the following lines of code at the top of the class, under the first curly brace:

You can adjust the “speed” variable to anything you like

The “speed” variable will dictate how fast the image will scroll and the _renderer variable is what gives us access to the image itself.

Don’t forget to access the MeshRenderer component within the Start() method:

The last line of code we need will put everything together and needs to be accessed from within the Update() method:

Time.time is the amount of time that has passed since the game began

Your complete script should look similar to this:

After attaching this script to the quad in the scene, press the play button and your background should start scrolling:

In our code we created a new Vector2 which we applied a variable to the x axis and set 0 to the y axis.

In order to move the background vertically, we can simply swap the 2 numbers like this:

change “speed” to “-speed” to move in the opposite direction

With very little effort, you can now scroll your backgrounds infinitely!

--

--