For the past week I have been working with Unity 4.3’s new 2D tools which were announced last week. Unity has been on my list of game frameworks to try out for years now but the thought of doing 3D games didn’t really appeal to me and trying to force it to do 2D didn’t sound like much fun either. But now with the addition of a completely new and well integrated 2D workflow I immediately jumped in and started picking it up. As a first time Unity user I am not going to focus too much on the process of actually building something, although I plan on writing more on the subject very soon. Instead I want to just cover the new 2D workflow and give you a sense of what it’s like to make a 2D game in the latest version of Unity which is still in beta.
When you first open up Unity 4.3 and create a project you are presented with a new default option for 2D as a drop down bellow the package import selection area.
By default it is set to the 3D. Once you make this selection and start your new project the scene will automatically be setup for 2D.
You’ll notice there is now a 2D toggle in the scene which basically locks the camera, sets it up for you and makes it incredibly easy now to start building a 2D game. You can go back to 3D at any time by simply unselecting the 2D button.
So for my own experiments I dragged over a copy of my free Resident Raver artwork folder, which I have been using in most of my games lately, into the Assets folder. From there I was able to select each graphic and they are automatically setup as a new sprite texture for me.
Unity now also offers the ability to bring in Sprite Sheets or Texture Atlases depending on what version of Unity you are using. The latter option is exclusive to Unity Pro. To do this, simply import a Sprite Sheet and open it up in the inspector.
From here you can change the Sprite Mode from Single to Manual and you will get a new option for a Sprite Editor
By clicking on it you can manually draw out the shape of each sprite or set up dimensions for it automatically slice them for you.
Here you can see it has automatically made a single sprite, but by changing this blue box around it you can make your own sprite sizes.
The other option is to change the mode from slice to grid in the Slice dropdown at the top left of the window.
The one thing to keep in mind is that you need to tell it how many rows and columns there are in the sheet.
Here it is setup as a 10 x 4 tile sprite sheet. Once you hit apply you will get something like this in your Asset folder.
As you can see by expanding out the texture you will now get all of the sprites to use as textures in other places of your game.
While I am still wrapping my head around the finer details of setting up sprite animations in Unity, here is quick walk through of how it works. First, select a bunch of sprite textures from the asset folder and drag them to the Scene windows. You will be immediately prompted to create a new Animation and save it.
Next it will ask you to create an Animation Controller.
Now you will have a new GameObject in the Scene along with the new Animation and Animation Controller in your Asset folder.
Once you run it you will see the animation play and you can begin to modify the new GameObject just like you would any other Unity GameObject.
Along with the new Sprite textures and animation workflow there is a new collection of 2D Physics components you can use in your game. All of these mirror the standard physics components so if you are familiar with Unity it shouldn’t be very hard to pick up how they work. For this example I created a simple background and floor for my demo game. To do this I split the artwork up into two Sprites and aligned them in the Scene to look like one image.
In the Scene you can change the render order of sprites by modifying their Order In Layer property. Here you can see I set the background Sprite to -1 so my Zombie shows up above it.
Next I wanted to add some gravity to my Zombie so I added a RigidBody 2D and Box Collider 2D component to it via the Add Component Button.
To keep the zombie from falling through the floor I added a Box Collider 2D to the floor as well. So now when I run the game the zombie falls and stands on the floor.
I also made some modifications to the zombie’s Box Collider to offset him better and make him look like he is walking in the middle of the carpet instead of directly on top of it. This is easy to do by simply offsetting the center of the zombie’s Box Collider 2D. Here is the final effect.
When it comes to detecting collision on the actual GameObject, you can simply add a method called onCollision2DEnter, just like you would for the normal collision component. You’ll find that by simply adding a 2D to most of the other hooks you are used to using they will work the same way in the 2D environment.
Get My New Unity 2D Book
Looking for a quick start guide to Unity 4.3′s new 2D workflow? Well look no further, my new quick-start guide will have you up and running in no time! You’ll learn the basics of animating 2D sprites, collision detection, Box2D, making things move and how to spawn enemies.
So this concludes my introduction to Unity’s new 2D tools. As you can see they are incredibly easy to work with and it only took me a few hours to figure out. Most of that time was really spend just trying to ramp up on how Unity actually works. These new tools are powerful enough to let you quickly stub out your 2D games with very little friction. I have already been asked a bunch of questions on how these stack up to the more popular 2D tools you can buy in the Unity store but since I haven’t spent much time with them I can’t say. For me, it’s nice to see how quickly I can get up and running in Unity with their built in 2D tools and I imagine over time the exiting 3rd party tools will simply build on top of this foundation.