Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Sprites have their own layering system, beyond the normal Unity layer system, and it allows us to stack flat sprites exactly on top of each other, but determine who renders, or who displays, first. What I'll do is to select my background and then start to get in some sorting layers for these sprites, so I can layer the cars over the background and create some parallax if needed. I'll pick that cars background texture. And, here in the inspector, we've got it all set. It's at 512 pixels per unit, true color and it's all sliced well as a single sprite with a pivot at the bottom.
I'll go into the 2D view in my scene. Pan down until I can find a blank space and drag this background object in. When I'm all done with the painting I'll nest all the elements under a game object and then move it around in the scene as I need. I'll zoom in on this object and what we can see here when we bring it in is that it creates a prefab just like any other asset. It's got a transform with no Z at the moment. The scale is 1 and it's got a new sprite render component. This bright render component has its own kind of material, and a color that we can use to tint that sprite if we need.
It also looks to that char's background sprite that I've defined, and there's a sorting layer and order to that layer. What I'll do first then is to drop down under default in the sorting layer and Add Sorting Layer. In the sorting layers, I can add by clicking the plus under default, and I'll name this new layer, background. Now I'll add on a cars one and cars two layer. These load from the top down, so if I put something on the background and then something else on cars one, cars one will be in front of it. You can drag these around if you need by grabbing the double bars next to the layer name and simply pulling it.
I'll leave these alone background cars 1 and cars 2 and with any sorting layer e actually have a sorting order of we need. I'll select this background object and change its sorting layer to background. Within that layer if you got multiple objects you can number them. This is like a ranging objects in Adobe Illustrator if you're familiar with that workflow or within one layer each object non destructively can lay over the ones in front and in back of it. And that way you can stack things correctly and define exactly what is showing first in your layers.
Now I'll get my cars in. In the cars here, at the bottom, Cars2D_4 is my giant background cars. This one is going to be more or less a static, and I'will put it in there by dragging it into the scene. In the sorting layers then, I'll put this on Cars 1 and it appears over the background. Now I'll snap it in place. There's a couple of ways to do this with a sprite. First, I can pick the background and put it maybe at a more round coordinate, how about negative 56? I'll also put the Y at 17.
This way it's just easy to type in. The pivot is on the bottom and that's what that position refers to. Now when I pick this cars one object here, and put its pivot in the same place, they'll match exactly. With the pivot of cars one down at negative 56 and 17, those cars are exactly stuck to the bottom over that sprite. I'm ready to get my other cars in. I'll pick cars 2D_0 and drag it into the scene as well. I'll put this sorting layer on layer two and then I'll pull in some other cars. Now I've got all of my cars in.
These top four clusters are on cars two and I can set the order in the layer. I'll start out by making this white car number one. I'll let the green be zero. This bottom green will come in as two and so on. Now that I've sorted all of them, put them on their layers and put in the sorting order within that layer, those cars will all draw in the right order and not overlap each other. When I take these cars and slide them over we can see that the cars cleanly move over because they're at the higher number in the layer.
Now I'll get my cars aligned. What I'll do then is to zoom in. What I would like to have happened is that the white car accelerates to bump into the green car which then will turn on its physics and fall down on to the others. I'll pick this white car and hold V for snap. What we get then is a registration of the snap at whatever the closest corner is on that sprite. I'll snap it over to the other car and then pull it back. Holding Shift constrains that motion. Now these two cars are snapped together, and I'll do the same with the next row down.
Holding V for snap, snapping them together, and then pulling back while holding Shift. My painting is ready to bring to life. I've established my sorting order and layers. And this way I get parallax if needed. Or at least the idea of these flat objects passing in front and behind each other. Like all things in unity, it's important to stay organized. So create layers and name them. And precisely figure out your order in your layer. This way you can avoid any Z fighting. Or places where the objects don't know who's on top, and each one competes to draw first.
Get unlimited access to all courses for just $25/month.Become a member
107 Video lessons · 32745 Viewers
94 Video lessons · 22685 Viewers
78 Video lessons · 8915 Viewers
83 Video lessons · 8250 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.