Introduction to Unity3D

Unity3D is a powerful cross-platform 3D engine and a user-friendly development environment. Learn how Unity3D can help you create games in this article!


What is Unity3D?

Unity3D is a powerful cross-platform 3D engine and a user friendly development environment. Easy enough for the beginner and powerful enough for the expert; Unity should interest anybody who wants to easily create 3D games and applications for mobile, desktop, the web, and consoles.


Cost

Indie developers rejoice, Unity is free! Well, almost. There is a Pro edition that comes with more features and tools, but will set you back $1,500. Considering the feature set and how permissive the Unity publishing license is, this price is actually very reasonable. However, the free version will let you get your feet wet, build complete games, and even publish them to the desktop and the web without paying a cent! The only caveat is that games published under the free edition will have a small Unity watermark.

Anything built in Unity will work exactly the same way in Unity Pro. This means you can choose to upgrade at any point if you need the additional features, or want to publish to more platforms such as iOS and Android. There’s also a 30 day Pro trial you can sign up for in order to test drive all the extra features!

A complete feature comparison between Unity and Unity Pro can be found here:

http://unity3d.com/unity/licenses


Installation

Installation is a painless two step process. First, download and run the Unity installer.

Unity Installer

Second, when you start Unity for the first time, it will open a web browser and prompt you to register using your email address. It will let you choose which version you want to run. You can select either the free version or a Pro trial that will fallback to the free version after 30 days.


The Application

The Unity application is a complete 3D environment, suitable for laying out levels, creating menus, doing animation, writing scripts, and organizing projects. The user interface is well organized and the panels can be fully customized by dragging and dropping.

Unity Application

The Project panel is where all the assets within a project are stored. When assets are imported, they will first appear here.

The hierarchy panel is where assets are organized in a scene. Assets from the Project panel can be dragged into the Hierarchy panel to add them to the current scene.

The Inspector panel lets you inspect and adjust all the attributes of a selected asset. Everything from its position and rotation, to whether it’s affected by gravity or able to cast a shadow.

The Scene panel is a 3D viewport where you can physically arrange assets by moving them around in 3D space. You can navigate the viewport by panning, rotating, and zooming the view. If you’ve used Maya at all, you should find these hotkeys familiar:

Mouse Button Shortcuts

When it comes to running your game, it couldn’t be simpler. Just press the play button. To stop it, press the play button again. You can even pause your game during play to inspect your scene.

Play Button

Unity Projects

A Unity project is an ordinary folder containing every resource that belongs to your game. Creating a new project is a straightforward affair.

  1. Click File > New Project
  2. Click the Create New Project tab
  3. Browse to a suitable folder
  4. Click Create
Create New Project Window

The result is a project folder containing subfolders named Assets, Library, and ProjectSettings.

Project Folder

Assets

Assets are any resource your game uses. These include 3D models, materials, textures, audio, scripts, and fonts, to name a few. Other than a few simple objects such as cubes and spheres, Unity can’t actually create most of these assets. Instead, they must be created externally using 3D modeling applications and painting tools and then imported into Unity.

Thankfully, Unity’s asset importing is robust and intelligent. Traditionally, 3D game engines have usually been finicky things and are very particular about what files you give them, forcing developers to carefully convert all their files. Not Unity. It will accept all popular 3D file formats including Maya, 3D Studio Max, Blender and FilmBox with all the rigging, materials and textures intact. Unity also supports all common image file formats, including PNG, JPEG, TIFF and even layered PSD files directly from Photoshop. When it comes to audio, Unity supports WAV and AIF, ideal for sound effects, and MP3 and OGG for music.

A complete list of all the formats Unity can import can be found here:

http://unity3d.com/unity/editor/importing

Let’s import an asset so we have something to work with:

  1. Download boxboy.zip
  2. Unzip it to your desktop
  3. Drag the boxboy folder (containing boxboy.fbx and texture.png) from your desktop into the Project panel
  4. Drag the boxboy asset from the Project panel into the Hierarchy panel
  5. Select boxboy in the Hierarchy panel
  6. Press F to focus the Scene panel on the boxboy

Note: Unity has an Asset Store where you can purchase 3D models, characters, textures, sound effects, music, tools, and even scripts. The Unity Asset Store has quickly become an invaluable resource for game developers and a money making venture for artists and tool developers.


Scenes

Scenes are where you can drag in project assets and arrange them to make levels and game screens. The Hierarchy panel represents the contents of the current scene in a tree-like format. While the Scene panel is ideal for arranging your scene’s assets in 3D space, the Hierarchy is where you’ll spend most of your time actually organizing your scenes and keeping them tidy.

When you start a new project, Unity automatically creates a new scene for you. Scenes start out with nothing but a camera. If you were to run the game now, you won’t see anything but the background color. To give us something to look at:

  1. Drag the boxboy asset we imported from the Project panel into the Hierarchy panel

    Dragging Asset to Hierarchy
  2. Select the boxboy asset in the Hierarchy panel
  3. In the Inspector, find the Transform component and adjust the position so that X, Y, and Z are all set to 0. This will ensure your asset is at the exact center of the 3D world.

    Transform Properties
  4. The default camera position isn’t very good, so let’s give it a better angle. Select the camera, then reposition it using the move and rotate tools.

    Camera Being Moved

Scenes are assets and should be saved in your project just like other assets. To save your scene:

  1. Click File > Save Scene
  2. Navigate to your project’s Assets folder
  3. Name your scene Main
  4. Click Save
Project With Main Scene

Scripting

Scripts, known in Unity as behaviours, let you take assets in your scene and make them interactive. Multiple scripts can be attached to a single object, allowing for easy code reuse. Unity supports three different programming languages; UnityScript, C#, and Boo. UnityScript is similar to JavaScript and ActionScript, C# is similar to Java, and Boo is similar to Python. Depending on your background you may feel more comfortable with one or the other.

Let’s create a C# script:

  1. Click Assets > Create > New C# Script
  2. Rename the new script in the Project panel to PlayerScript
  3. Double click the script to open it in MonoDevelop

The script should look just like this:

Note: C# class names must be the same as their file name and are case sensitive. Make sure your class name matches the file name exactly, excluding the file extension.

All scripts have a start() method and an update() method. The start() method is run once when the object is first created, while the update() method run once per frame. Our script needs to be constantly checking for arrow keys being pressed, so we’ll add the following code to the update() method.

Now that our script is done, we need to assign it to our asset. Naturally, Unity makes this a simple affair:

  1. Drag the script onto the boxboy asset in your scene

With the script assigned to our boxboy asset, we can run the game and move BoxBoy around by pressing the arrow keys.


Publishing

Unity is able to publish to Windows, OS X, and the web via the Unity Web Player. The Web Player is a browser plugin that works in all major browsers and offers the same performance available on the desktop.
You can download the Unity Web Player here:

http://unity3d.com/webplayer/

Not surprisingly, Unity Pro can publish to even more platforms, including iOS, Android, Wii, Xbox 360, Playstation 3 and even a Flash version of the Web Player.

To publish our game for the Web Player:

  1. Click File > Build & Run
  2. Select Web Player from the list
  3. Click Build And Run
Unity Web Player

Conclusion

Click here to download the complete Unity project.

This article barely scratches the surface of what is possible with Unity. If this introduction has whet your appetite for more 3D game development, be sure to check out the following resources:

Tags:

Comments

Related Articles