Looping Backgrounds

Al Heck
2 min readMay 17, 2021

Objective: How to create a moving looping background for our sprite using material.mainTextureOffset = new Vector2(0, _offset);.

First thing we need to do is to make sure our image tiles correctly. Since we’re going top to bottom, let’s adjust the image by going filter/offset to see where the edge will occur.

We see the issue. As we move, we will create a situation where the edge is obvious where we loop. Select this area and do a content awareness fix or use a stamp tool to clean it up.

Now we have a seamless background. Now bring this into Unity.

Let’s create our background plane, drop it back into the Z axis so our player ship flies over it, and attach a new material with the texture on it. Set it to mobile/unlit to remove any specular or shadows.

We then need to create a simple script. We want to grab the material by storing the renderer component. We then want to use material.maintextureoffset and shift it based off of an offset value. Now our background moves at a set pace.

--

--

Al Heck

Unity Developer and Software Engineer who loves making games with GameDevHQ