In this video, Jesse Freeman teaches you how to create the background of your endless runner game as a repeating background. By using a simple quad and a texture that repeats you'll be able to optimize your game. Working with repeating textures, quads and GameObject's dimensions in Unity 5 are important skills for building a 2D game.
- [Voiceover] So now that our camera is automatically set up to resize itself, based on the resolution of the game. We can go in and start building out the level for our game. Let's select all these items that we were testing with, and delete them from the hierarchy view. Also, we'll wanna set the camera back to size 80, this way, when we're laying things out, we'll be able to see them in the game preview. For now, we'll leave it at 1024 X 768. You'll see that we're using a resolution of 360 by 270, because my monitor's a little bit smaller.
If I was to increase this or decrease this, you would see a larger resolution size. Likewise, when you're testing, you can do maximize on play, to see the full screen. So in order for us to do the background, we're gonna need to go back into our artwork folder, and take a look at our texture. Let's start with the wall texture. Now, by default, this was imported as a sprite. Here, we're gonna convert this back into a texture, then, what we can actually do, is modify the rap mode, to allow it to repeat.
We still wanna change the filter mode to point, and we can go back to the format, and we can set this to true color, and hit Apply. Now, our texture will repeat whenever we add it to a surface, in this case, let's create a simple game object, that will allow us to apply the texture and represent our background. We'll go to the Game Object menu, we'll go to the 3D List, and we'll create a Quad. Now, the quad is gonna be really small, because the pixels to units in our game are so high.
If we double click on our quad, and zoom in, we'll take a look at what this is. It's very similar to a plane, but it's actually comprised of two triangles. If we were gonna go into 2D mode, you would see that the quad disappears, because there's no background texture for it. Now, I like to use quads because one, they're very efficient, and two, they allow me to do things like re,size them and scale them, and give me a large surface to attach artwork to, especially a background in a 2D game.
Now, let's change this quad to match the size of the texture we're gonna apply to it. We're gonna go over to it's scale, and set this to 32 by 32. Again, if we double click on the quad in the hierarchy, we'll zoom out, and here, we'll get a good estimate of what this is looking like in our game. Next, we're gonna wanna change the Z of this object, to be a little bit further away from the camera. Now, when we work in a 2D part of unity, we don't actually have to worry about Z, but because this is a 3D object, and we're gonna add a few different quads over the next few videos, we wanna make sure that they're layered correctly.
In this case, we're gonna set it to two, which will push it further away from the camera. To give you a point of reference, if you look at the camera, the Z index for the camera is set to negative 10. Now, back on our quad, you'll see it looks kind of boring. Now, in order for us to actually apply a texture to it, we're gonna have to create something called the material. In our Assets folder, let's create a new folder called Materials. And inside of Materials, we're gonna create our first material.
Let's call this Wall Texture. Now, for the point of this course, we're just gonna pick a very simple shader, that will help us render the texture, in a way that will let us repeat the background. Shader's alter the way the materials look in the game. In this case, we're simply gonna go to Mobile, Particles, Alpha Blended, and you'll see, the options have now changed, based on the shader that we're using. Here, we can select a texture. We'll hit the Select button, and we'll scroll down, and we'll find our Wall Texture.
Now we have our Wall Texture set. If we were to drag this Wall Texture over to our quad, you'll now see that our wall texture appears in the background. In the next video, we'll talk about how tiling works, and how to re-size this, so that it fills up the entire screen.
Start watching to learn how to convert artwork into sprites, create repeating background textures with Unity's TexturePacker, and build reusable game objects such as players, obstacles, and enemies. Jesse also covers the basics of object pooling, working with custom UI components, and multiplatform publishing.
- Importing artwork
- Editing sprites
- Creating repeating background textures
- Building reusable obstacles
- Recycling game objects
- Building an object pool
- Creating the player
- Starting and ending the game
- Displaying and saving the score
- Adding menus and text
- Publishing a Unity game in different formats