From the course: Learning Unity 2D Sprites

2D camera - Unity Tutorial

From the course: Learning Unity 2D Sprites

Start my 1-month free trial

2D camera

- [Instructor] Before we move on, let's take a look at the camera. If you've already tried to run the game, and as you can see, in the game preview window below, all of our artwork is incredibly small. Let's select the camera, and take a look at some of the settings. The first property of the camera is the Clears Flag. By default, it's set to Skybox. We can go ahead and change this to a solid color, since most 2D games don't have a Skybox, like you'd have inside of a 3D game. Next is the background color. We're going to leave this set to blue by default, but in your own games, you can change this by simply clicking on it, and picking a new color. The Culling Mask allows us to define the area outside of the camera that is clipped. We can leave this at default. But the two important areas for us to focus on, is the projection, and the size. Since we've set up this project as a 2D project, the camera's projection is automatically set to Orthographic, which will allow us to see all of the images in the camera's view on the same plane. If we were to change this to Perspective, you'll see on the game preview, that things got a little bit distorted and scaled. While you can use a perspective camera in 2D, for most games, you're going to want to stick with orthographic. In fact, there are all different kinds of ways that we can emulate Parallax scrolling, which is when the background moves slower than the foreground to give the sense of depth without actually using real 3D space. Remember, all of Unity's games are running in a 3D world. You can actually preview what is going on, by going to the Scene, and clicking the 2D tab. Here you'll see that the space is now changed to the 3D view, showing us our sprites in 3D space. If we select 2D again, the scene's camera snaps to the orthographic view, giving us a more accurate representation of what we would see in the game itself. In this view, changing the Z depth of sprites has no effect. But, one problem we have is that all of our sprites are very tiny. To handle that, we're going to change the size of the camera, in order to zoom in or out of our scene, based on what we feel is best. You can hover over a property in the inspector, and you'll see your icon change to a cursor with two arrows. If you click down and drag to the left or the right, you can change the value. Let's go ahead and find a scale that makes a little bit more sense. Here, we're going to set this to something close to 0.35. This may change depending on your computer's resolution, and how you have the game view set up. As an example, our game's preview panel is set to Free Aspect, meaning it will scale and show you as much as possible within the view you allow it. If we clicked on the Free Aspect menu, and select something like 16:9, you'll now see that the camera crops based on the current aspect ratio. As you continue to build 2D games, especially where using multiple resolutions on different devices, or different computers, you'll want to account for the fact that each device has a different resolution. And while designing to a specific aspect ratio helps alleviate that, it isn't always a sure bet that the camera size will be the same on each computer. One thing you'll want to do as you get more skilled in working with Unity, is learn how to build a pixel-perfect camera. A pixel-perfect camera takes the depth of our scene into account, and automatically changes the size to show the sprites at their ideal resolution. This way each pixel looks clean and crisp, no matter what resolution the device is running on. If you want to learn more about making pixel-perfect cameras, take a look at my Unity 5: 2D Essential Training course, where I go into more detail about how to build that. Since we're going to focus solely on how to work with sprites and animations, we'll just change the camera's size manually, feel free to play with the size, until you're comfortable with it, as you work on it in the scene. You can always go back to the Free Aspect ratio to have the game view better match what we see in the scene preview above.

Contents