Aucun résultat trouvé
Unity is the de facto game framework and IDE for a lot of the success stories you read about on multiple platforms. The IDE is very polished and easy to use. As Unity was previously just a 3D tool, there was a certain level of knowledge you needed before getting started. Now with the addition of an all-new 2D workflow, things have gotten a lot easier for game developers looking to build simple, non-3d games. In this post we’ll take a look at how the Unity IDE works for 2D game development.
Over the next few sections, we will take a look at the IDE itself and how to navigate around it and GameObject, which are the building blocks of your game. There are a lot of resources out there on Unity, but for people who have never opened it up before, this post will help get you acquainted with the basics in the IDE.
When you create a new project in Unity, you will see the following wizard:
As you can see, you are given an option to set the location of where you want to create your project, as well as packages you can include when it is created. The final thing to note, which is new in Unity 4.3, is the 2D setup tab at the bottom of the window.
By setting this to 2D, your project will automatically be configured for 2D game development. Let’s create a project called SPMS2D and toggle 2D.
Once you create your project, you will go into the editor and see the “Welcome To Unity” screen. I highly suggest going through some of the videos to learn more about how Unity works and get a sense for the workflow. Most of it is geared toward 3D, but it still applies to the stuff we will go over in this blog. I also suggest checking out the forums since there is a lot of really good information on there that can help you out when you get stuck as you are getting started learning Unity.
At first, Unity may be a little intimidating, but I personally find that the new 2D mode actually simplifies things greatly. Here is a high-level overview of the IDE. When you first open up a project in Unity you will see the following window.
Let’s go over each section of the IDE’s window by window. First, we’ll start with the main area.
This is where you will lay out objects, preview and test your game, and also work on animations and other visual-based activities. As you can see from the tabs, the Scene and Game tabs are already open. Below the tabs, you will see a few quick-access menus. The most important is the 2D toggle, which is already activated. By unchecking it, you will go back into Unity’s native 3D view.
I’m not going to go into the 3D navigation tools since we will be focusing on 2D instead so let’s look at the Hierarchy panel.
As you add stuff to your scene, you will be able to see and access them from here. For now there is a single object, which is the camera. Also, you have access to a Create shortcut menu, which we will be using a little later on. The same options can be accessed in the IDE’s top menus as well.
While you are looking at the Hierarchy tab, select Camera so we can discuss the Inspector panel next.
Here you can see all of the properties that make up the camera for our game. Unity does a great job of visualizing all the parts that can be configured on each object in your Scene. The Inspector panel not only allows you to modify values, even on the fly while the game is running, but it also lets you add additional functionality onto any GameObject via the Add Component button.
We will get into some of these components a little later on, especially scripts, which will make up a huge part of your coding experience. For now, it’s important to note that a GameObject is anything in the game itself and may be the camera, the player, or even more complex objects like levels, UI or even utilities we build to help us visualize elements in the game. Next up is the Project tab.
Think of this as a view into the project folder itself. To help you better understand it, go to where you created your project on your system and open it up.
As you can see, in addition to all of the additional files that make up the Unity game project, you will see there is an Assets folder. This becomes your default location for everything you put in your game. Here we will store artwork, sounds, scripts, and prefabs, which are reusable pre-configured GameObjects.
The final two things I want to cover may be self-explanatory but are always useful to review. In the upper-left corner you have a set of controls to help you navigate the Scene window.
While these tools are mostly focused around navigating a scene in 3D mode, they don’t have much use in 2D mode. When working in 2D the tool you will use the most is the Hand to simply drag the screen around on the x- and y-axis.
The other set of controls handles playback and allows you to test the game.
Simply hit Play to start the testing in the Game tab.
You will also notice the Pause and Step-Forward buttons. These are incredibly helpful in allowing you to move through the game frame by frame to see what is going on. You can also go back to the Scene tab while playing the game and modify values of GameObjects at runtime. It’s important to note that any changes you make in the Inspector panel while running the game don’t get saved; it simply allows you to try things on the fly without having to stop testing, make a change, and recompile.
Before we get into the coding and specific 2D tools, I wanted to provide some information about GameObjects, which are the building blocks of a Unity game. As you begin to flesh things out, you will start by creating these GameObjects in the Scene. Some of them will represent your Player, bad guys, and level while others will make up utilities and Gizmos, which we will learn about later on, to help you manage other GameObjects in the game.
To get you used to working with GameObjects, let’s just create a simple cube and position it in our Scene. Go to the GameObject menu at the top, or the Create menu from the Hierarchy panel, and select Cube.
Now, if you check your Hierarchy panel, you will see the cube and the camera. Select the cube to bring it up in the Inspector panel.
If you run your game now, you will not see the cube. Likewise, you can click on the camera to preview the Scene without even hitting Run.
We can fix this by adjusting the cube’s z-axis in the Inspector window to 0.
Now, if you run the game, you will see the cube.
Notice that we still have the Inspector panel open with the cube. You can continue to play with the cube’s properties while the game runs. If you roll over any number property, you will see the cursor change into a two-sided arrow, and you can use that to click and drag the value in the field up and down. Give it a try with the x and y properties of the cube. Since we are in 2D mode, modifying the z-axis will not do anything eventful. When you stop running the game, all of the values will reset themselves.
At this point you sound be familiar with the Unity IDE and the new settings for working in 2D. In the next post I’ll cover a primer on C# in Unity and how to start making basic scripts for your own games. Stay tuned!
Also, don’t forget that to checkout Amazon’s GameCircle plug-in for Unity to help you integrate cross-platform leaderboards, achievements, and game data synchronization. The plug-in works on iOS, Android, and Fire OS plus with the built-in Whispersync for Games component you can back up all of your user’s game data to the cloud across all three platforms. You can now download it from the Scripting/Integration section of the Unity Asset Store.
Introduction to Unity Part 2: Learning C#
- Jesse Freeman (@jessefreeman)