Introduction to Unity 3.5

Unity

Unity


In this article, I will introduce you to the Unity game editor. Unity is a tool for creating and deploying games to PC, consoles, web and mobile devices. In this post, I will go through the steps to get Unity installed on your computer and I will introduce you to the basic features of Unity. Unity makes it easy for anyone to get started making games. You will not need any previous game development experience to follow these articles but by the end, you will be prepared to start making your own games like a professional!

 

Installing Unity

The first thing you have to do before you can start using Unity is install it. Navigate to http://unity3d.com/ and click the “Download” link on the top-right of the page.

On the download page, click the “Download Unity” button. Once the file has been downloaded, execute the installer on your PC.

Installing Unity (1)

Installing Unity (1)

The Unity setup screen should appear. Click the “Next” button.

Agree to the licensing terms to continue.

Installing Unity (2)

Installing Unity (2)

Select all of the available components options and click the “Next” button to continue.

Installing Unity (3)

Installing Unity (3)

Select the folder where you want Unity to be installed and click the “Install” button.

If everything went okay, you should see the following screen.

Installing Unity (4)

Installing Unity (4)

Click the “Finish” button to close the installer and run Unity.

Unity comes with an example project called “AngryBots” that you can open if you don’t yet have a Unity project to run. I will use this example project in this article to demonstrate the different parts of the Unity editor. By default, the AngryBots example project is installed in “C:\Users\Public\Documents\Unity Projects” on Windows 7.

If you didn’t install the example project, or you would like to install a different example project, you can download additional example projects from the Unity Asset store which is accessible directly in the editor.

Learning the Interface

The first time you open the Unity editor, you will see a few of the default tabbed windows called Views open.

Unity Interface

Unity Interface

The image above shows the Unity editor with the “Tall” layout applied.

The Main Menu

The Main Menu is the menu at the top of the application window. It is organized into a logical set of “tasks” that you would need to access while you work on the project.

The File Menu

The File menu contains menu items that are used to create and open Scenes and Projects. A Scene can be a single level of your game, or a scene can be used to define the main menu for your game. A Project is the collection of things that is needed to create a game such as art assets, audio assets, scripts, and also the different game scenes.

Unity - File Menu

Unity – File Menu

The Edit Menu

The Edit menu contains the typical items you would expect in an edit menu such as Cut, Copy, Paste, Undo, Redo and it also contains items to modify the Editor Preferences as well as Project specific options and Render options.

Unity - Edit Menu

Unity – Edit Menu

The Assets Menu

The Asset menu is used for creating new assets or Importing assets from external files. You can also Import standard asset packages (standard asset packages are provided by Unity Technologies) as well as Import and Export custom asset packages for use in other projects (custom asset packages are user created).

Unity - Asset Menu

Unity – Asset Menu

Generally speaking Assets are the files that are created outside of Unity. Unity has fantastic support for a lot of different Asset types including 3D models, image formats, audio & video formats, and XML file formats.

Type External Package Extension Requirements
3D Model Maya .ma & .mb Must have Maya 8.0 or newer installed.
3D Studio Max .max Must have 3D Studio Max installed.
Cheetah3D .jas Must have Cheetah3D 2.6 or newer installed.
Cinema 4D .c4d Must have Cinema 4D 8.5 or newer installed.
Modo .lxo Must have Modo 501 or newer installed.
Lightwave .fbx Models must be exported to FBX format.
Blender .blend Must have Blender 2.45-2.49 or 2.58 or newer (versions 2.50-2.57 broke the FBX exporter in Blender).
COLLADA .dae Natively supported by Unity.
Autodesk FBX .fbx Natively supported by Unity.
Wavefront .obj Natively supported by Unity.
3D Studio .3ds Natively supported by Unity.
Drawing Interchange .dfx Natively supported by Unity.
Image Photoshop .psd Natively supported by Unity.
Other Image Formats .jpg, .png, gif, .bmp, .tga, .iff, .pict, .dds, and more… Natively supported by Unity.
Audio MP3 .mp3 Natively supported by Unity.
Ogg Vorbis .ogg Natively supported by Unity.
Other Audio Formats .aiff, .wav, .mod, .it, .sm3, and more… Natively supported by Unity.
Video Video Formats .mov, .avi, .asf, .mpg, .mpeg, .mp4 Video files are transcoded by Unity.
Other Other File Formats .xml, .txt Text files are not converted.

Unity supports almost every file type that you would want to use in your own games.

GameObject Menu

The GameObject menu contains items that allow you to Create and Manipulate GameObjects.

Unity - GameObject Menu

Unity – GameObject Menu

A GameObject is something that exists in a Scene. At its most basic level, a GameObject consists of a 3D position and an orientation in the Scene. The GameObject‘s position and orientation in the Scene is also called its Transform.

On its own, a GameObject does not do much. You must attach some Asset (as a Component) to a GameObject for it to be useful. You can also link GameObjects together in a hierarchical fashion with a “parent-child” relationship and the “child” GameObjects will then be defined relative to its “parent” GameObject. A GameObject can only have one parent so it is not possible to have the same GameObject linked to multiple parents but something similar can be achieved using Prefabs (which I will discuss later).

The Component Menu

The Component menu lets you add Components to the currently selected GameObject.

Unity - Component Menu

Unity – Component Menu

A Component must be added to a GameObject because a Component cannot exists on its own. The Components that are added to a GameObject define its behavior.

Unity has many types of Components that serve different purposes.

  • Mesh Component: used to render a 3D model at the location of the GameObject in the scene.
  • Effect Component: allows you to create a particle effects, or special lens effects in your game.
  • Physics Component: add physics to GameObjects so they can be physics controlled and able to interact with the player and other physics enabled GameObjects.
  • Navigation Component (Pro Only): Components that utilize the pathfinding functionality in Unity. The NavMesh funcitonality is only available for Pro licenses.
  • Audio Components: add sound effects to your game.
  • Rendering Components: components that control graphics related functionality such as cameras and lights.
  • Miscellaneous Components: Components that don’t fit in their own category.

You may see additional menu items in the Component menu if your project has any scripts which will be added to the menu when they are added to the project.

The Terrain Menu

The Terrain menu has commands for creating and manipulating terrains.

Unity - Terrain Menu

Unity – Terrain Menu

The Window Menu

The Window menu allows you to show and hide the different windows in the Unity editor. You can also change the current window layout or save a custom layout.

Unity - Window Menu

Unity – Window Menu

I will discuss the different windows in the following sections.

The Help Menu

The Help menu provides commands for accessing the documentation and also for registering your Unity version with a Pro license.

Unity - Help Menu

Unity – Help Menu

The Toolbar

The Toolbar contains a minimal set of tools that are required to interact with the Scene and to manipulate the GameObjects in the Scene.

Unity - Toolbar

Unity – Toolbar

Transform Tools

The Transform tools are probably the most common tool you’ll be using to interact with the Scene view and to manipulate the positions and orientations of the GameObjects. However, once you learn the shortcut keys, you probably won’t use this tool directly very much.

View Manipulation

The first (left-most) button on this tool is the scene view manipulator and its functionality is dependent on whether you are pressing the Alt key (Command key on Mac) on the keyboard. Pressing Q on the keyboard will switch to the view manipulation mode in the scene.

  • Unity - Pan View – (LMB) The Pan View button allows you to pan the scene view using the Left Mouse Button (LMB). This option can also be accessed with the Middle Mouse Button (MMB)
  • Unity - Rotate View – (Alt+LMB) The Rotate View allows you to rotate the scene view around the view pivot. This option can can be accessed by holding the Alt key on the keyboard and dragging in the Scene view with the Left Mouse Button (Alt+LMB).
  • Unity - Zoom View – (Alt+RMB) The Zoom View allows you to zoom in or out. This option is accessed by holding the Alt key on the keyboard while dragging with the Right Mouse Button (Alt+RMB).

GameObject Manipulation

You can transform GameObjects using the Move, Rotate, and Scale tools.

  • Unity - Move Tool – (W) The Move button allows you to manipulate the translation of the currently selected GameObject. The shortcut key for this tool is the W key.
  • Unity - Rotate Tool – (E) The Rotate button allows you to manipulate the orientation of the currently selected game object. The shortcut key for the rotate tool is the E key.
  • Unity - Scale Tool – (R) The Scale button allows you to manipulate the scale of the currently selected GameObject. The shortcut key for scaling an object is the R key.
Unity - Transform Gizmo

Unity – Transform Gizmo

The Transform Gizmo shown in the image above allows you to constrain the translation, rotation, and scale to a particular axis or axes.

Clicking on the Red gizmo handle allows you to constrain the manipulation in the X-axis.
Clicking on the Green gizmo handle allows you to constrain the manipulation in the Y-axis.
Clicking on the Blue gizmo handle allows you to constrain the manipulation in the Z-axis.

When using the Translate Gizmo, you can press the Shift key on the keyboard to constrain the movement to the View plane (motion is constrained to the virtual plane represented by the screen).

Gizmo Tools

The Transform Gizmo manipulation tools allow you to specify how the gizmo behaves.

Unity - Gizmo Tool

Unity – Gizmo Tool

Pivot

You can specify that the Transform Gizmo should be relative to the GameObject’s pivot point. In this case, any transforms that you apply to the GameObject (or selected GameObjects) will be relative to that object’s pivot point.

Unity - Gizmo (Pivot, Global)

Unity – Gizmo (Pivot, Global)

The image above shows that the Transform Gizmo is anchored to the currently selected GameObject’s pivot point. When selecting multiple GameObjects, the pivot point will be anchored to the GameObject that was selected first.

Center

You can also specify that the Transform Gizmo should be relative to the GameObject’s center point. This may be different than the pivot point of the GameObject if the GameObject is parented to another GameObject in the scene Hierarchy or if it contains a model (or mesh) that does not have it’s pivot centered in the model.

Unity - Gizmo (Center, Global)

Unity – Gizmo (Center, Global)

The image above shows that the Transform Gizmo is centered relative to all the currently selected game objects. Any rotations applied to the selected GameObjects will be relative to the center point of all of the currently selected GameObjects.

Global

With Global selected in the Gizmo tool, translations and rotations will be applied in the global reference frame (that is, the global X-, Y-, and Z-axes). In this case the GameObject’s orientation will be ignored when using the Transform Gizmo to translate or rotate the GameObject.

Scaling a GameObject will always be applied in the GameObject’s Local space. Otherwise the GameObject might become skewed which is usually undesirable.
Unity - Gizmo (Global)

Unity – Gizmo (Global)

You can see from the image above that the Transform Gizmo is still aligned to the Global Axis even after the GameObject has been rotated.

Local

With Local selected in the Gizmo tool, translations and rotations will be applied in the GameObject’s local reference frame. In this case, the GameObject’s current orientation will be taken into consideration when transforming the GameObject using the Transform Gizmo.

Unity - Gizmo (Pivot, Local)

Unity – Gizmo (Local)

Game Player Controls

The Game Player controls allow you to play the game directly in the editor.

Unity - Game Player Controls (Play, Pause, Step)

Unity – Game Player Controls (Play, Pause, Step)

The Game Player controls will turn blue when the game is currently running.

  • Play: Start/Stop the game play in the Game Window.
  • Pause: Pauses the currently playing game. If the game is not playing, it will be started in the “Pause” state when you press the “Play” button.
  • Step: Step and Pause the game play. Successively hitting this button will run the game in a single-step iterations of the game loop.

The Layers Tool

Each GameObject can be assigned to a particular layer. By default, newly created GameObjects are created in the “Default” layer. The visibility of GameObjects in the Scene can be toggled on and off by selecting the layers in the layers visibility drop-down list.

Unity - Layer Visibility

Unity – Layer Visibility

The Layout Tool

The Layout drop-down list can be used to quickly set your workspace to a predefined layout.

Unity - Layout Tool

Unity – Layout Tool

The Layout drop-down list also lets you save your current layout if you have made any changes to one of the default layouts. Saving your current layout allows you to create a set of layouts that you commonly like to use.

The Editor Windows

The Unity Editor currently has ten different windows that can be used to view different aspects of your game project. By default, the Scene, Game, Hierachy, Project, and Inspector views are visible. In this section, I will discuss each view and it’s uses.

The Scene View

The Scene View (Ctrl+1) is used to position and orientate the GameObjects in the scene. Some components provide additional handles you can manipulate in the scene view when holding the Shift key on the keyboard.

Unity - Scene View

Unity – Scene View

Navigating the Scene View

There are multiple ways to navigate the scene view.

Arrow Keys

If the Scene views have focus, you can use the arrow keys on the keyboard to fly through the level. The Up/Down arrow keys will move the camera forward and backward relative to the direction the view. The Left/Right keys will pan the view left and right respectively.

You can use the Shift key to double the movement speed.

Flythrough Mode

Holding down the Right Mouse Button (RMB) in the Scene view will allow you to Flythrough the scene using familiar FPS controls. In this mode, you can use the WASD keys on the keyboard to move forward, left, back, and right (respectively). Using the Q and E keys you can fly down and up (respectively).

You can use the Shift in this mode as well to double the movement speed.

Zoom to Selected

Selecting a GameObject in either the Scene view or the Hierarchy will allow you to quickly zoom to that GameObject in the Scene view by pressing the F key on the keyboard while the mouse is over the Scene view. The Scene view will zoom to the GameObject (and all of it’s children) centered in the view. This will also center the camera orbit on the GameObject.

The Scene Gizmo

You can use the Scene Gizmo to orient the current scene view.

Unity - Scene Gizmo

Unity – Scene Gizmo

Clicking on any of the axis on the gizmo will snap the view to that orientation. Clicking in the center of the gizmo will go back to Perspective view.

Unity - Scene View

Unity – Scene View

Shift-Click on the middle of the Scene Gizmo to toggle between Perspective view and Isometric view.

Unity - Perspective vs Iso

Unity – Perspective vs Iso

Draw Mode

You can change the way the scene is viewed using the Draw Mode drop-down box.

Unity - Draw Mode

Unity – Draw Mode

Textured Draw Mode

The Textured draw mode allows you to see the scene with all of the models textured.

Unity - Scene View

Unity – Scene View (Textured)

Wireframe Draw Mode

In Wireframe draw mode, all of the meshes are drawn using their wireframe representation.

Unity - Wireframe View

Unity – Wireframe View

Tex – Wire Draw Mode

In Tex – Wire draw mode, you see the textured models with their wireframe representation drawn on top of them.

Unity - Tex - Wire

Unity – Tex – Wire

Render Paths Draw Mode

In Render Paths draw mode, each object is shaded based on the rendering path used to render the object.

  • Green – Deferred Rendering.
  • Yellow – Forward Rendering.
  • Red – Vertex-Lit Rendering.
Unity - Render Paths

Unity – Render Paths

Lightmap Resolution Draw Mode

The Lightmap Resolution draw mode shows the textured objects with an overlay of a checkered grid which represents the resolution of the lightmaps for each object.

Unity - Lightmap Resolution

Unity – Lightmap Resolution

Light Probes Draw Mode

With the Light Probes draw mode selected, you can visualize which light probes will effect the currently selected object.

Note: The AngryBots sample project does not use light probes so selecting this view mode with the AngryBots scene does not look any different than the Textured view mode.

Render Mode

The Render Mode drop-down box allows you to select the current render mode for the scene.

Unity - Render Mode

Unity – Render Mode

RGB Render Mode

The default mode is RGB render mode. In this render mode, object are rendered normally.

Unity - RGB Render Mode

Unity – RGB Render Mode

Alpha Render Mode

The Alpha render mode displays the alpha value of the objects texture or material. This does not mean that objects that are drawn black in this render mode will be transparent. They must have a transparent material applied on them in order to be rendered in the transparency pass.

Unity - Alpha Render Mode

Unity – Alpha Render Mode

Overdraw Render Mode

In Overdraw render mode you can see where objects are drawn over top of other objects. Darker areas have less overdraw where brighter areas indicate overdraw.

Excessive overdraw could result in poor rendering performance but is sometimes unavoidable.

Unity - Overdraw Render Mode

Unity – Overdraw Render Mode

Mipmaps Render Mode

In Mipmaps render mode you can visualize ideal texture sizes using a color code.

  • Red: The texture is larger than necessary.
  • Blue: The texture could be larger.

Keep in mind that the resulting colors is dependent on the current resolution of the screen and the distance the camera is away from the objects. Generally, you should see objects turning blue when you move the camera close to them and objects that are far away will generally be red. Unity will automatically generate mipmaps for your textures when they are imported.

Unity - Mipmaps Render Mode

Unity – Mipmaps Render Mode

Scene Mode Controls

The Scene Mode controls allow you to enable or disable different aspects of the scene view.

Unity - Scene Mode Controls

Unity – Scene Mode Controls

  • Scene Lighting: Unity - Scene Lighting Toggle the game lighting or the scene default lighting.
  • Game Overlay: Unity - Game Overlay Toggle the display of Skyboxes and GUI Elements in the Scene view.
  • Audition Mode: Unity - Audition Mode Toggles playing of audio sources in the scene view.

Search Filter

You can use the object search filter on the top-right side of the Scene view to quickly isolate specific game objects.

Unity - Search Filter

Unity – Search Filter

In this case, I filter on objects with the name “Player”. The search filter is capable of filtering using partial names so both the “Player” GameObjects are isolated and the “PlayerSlideDoor” GameObjects are also isolated in the scene view.

The Game View

The Game View (Ctrl+2) allows you to see how the game will look during production.

Unity - Game View

Unity – Game View

On the top of the window, you will see the Aspect drop-down menu, the Maximize on Play toggle button, the Stats toggle button, and the Gizmos toggle.

  • Aspect: The Aspect drop-down menu allows you to force the aspect ratio of the Game View so that you can see how your game will play at different aspect ratios.
  • Maximize on Play: This toggle button will cause the Game View to maximize to 100% of the editor window.
  • Stats: The Stats toggle button will toggle the display of the performance statistics.
  • Gizoms: Pressing this button will allow you to visualize the Gizmos that are usually only drawn in the Scene view.
Unity - Game View (Stats On)

Unity – Game View (Stats On)

The Inspector View

The Inspector View (Ctrl+3) shows you the properties of the currently selected GameObject and all of it’s Components.

Unity - Inspector View

Unity – Inspector View

One component that is common to all GameObjects is the Transform component. You will never see a GameObject without this component and it is impossible to remove the Transform component from a GameObject.

We will use the Inspector view more when I discuss Components and game scripting.

The Hierarchy View

The Hierarchy View (Ctrl+4) shows all of the GameObjects in your scene. You can either select a GameObject directly from the Scene View or you can use the Hierarchy view to select a GameObject that exists in your scene.

Unity - Hierarchy View

Unity – Hierarchy View

Using the Unity - Create Game Button (create new GameObject) you can quickly add a new GameObject to the scene based on one of the GameObject templates provided.

The Project View

The Project View (Ctrl+5) is a direct reflection of the Asset folder in your game’s root folder on your file system.

Unity - Project View

Unity – Project View

In the Project View, you can use the Unity - Create New Button to add a new asset type to your game assets.

I will discuss the project view in more detail when we create a new project from scratch.

The Animation View

The Animation View (Ctrl+6) allows you to create and modify Animation clips on the currently selected GameObject.

Unity - Animation View

Unity – Animation View

I will discuss how to use the Animation view in a future article.

The Profiler View (Pro Only)

The Profiler View (Ctrl+7) allows you to profile and optimize certain aspects of your game.

Unity - Profiler View

Unity – Profiler View

The Profiler View is only available in the pro version of Unity.

The Particle Effect View

The Particle Effect View (Ctrl+8) is used to manipulate particle effects.

Unity - Particle Effects View

Unity – Particle Effects View

I will discuss creating particle effects in another article.

The Asset Store View

You can use the Asset Store View to download plug-ins and content that can be used in your Unity project.

Unity - Asset Store

Unity – Asset Store

The Asset Store has a lot of free and paid plug-ins and game content.

The Asset Server View (Team License)

The Asset Server View requires the Asset server license or a Team License to access it. The Asset Server (Ctrl-0) is a content versioning system that makes it easier to share code when working in large teams.

Other Windows

There are several other windows that you can also access from the Window menu.

Lightmapping

The Lightmapping view allows you to access the lightmapping settings and controls for the current scene. Lightmapping is used to apply a pre-rendered version of the lighting contributions to static objects in the scene.

Both the free version and the pro version of Unity allow you to access the Lightmapping view, the pro version has a lot of extra settings that cannot be accessed in the free version.

Unity - Lightmappig View

Unity – Lightmappig View

I will discuss Lightmapping in more detail in another article.

Occlusion Culling (Pro Only)

The Occlusion Culling View allows you to specify parameters to generate the occlusion data. You can bake the occlusion data as a pre-process step. This allows Unity to optimize the visibility determination of GameObjects and reduce the chance that occluded objects are rendered.

Unity - Occlusion Culling

Unity – Occlusion Culling

Navigation (Pro Only)

The Navigation View allows you to generate navigation information for use by the game AI.

Unity - Navigation View

Unity – Navigation View

Creating Your First Project

Now that we have a good understanding of all of the different parts of the Unity Editor, let’s put that knowledge to good use by creating our first project.

Open the Unity Editor if it is not open already. By default, Unity will open the last opened project project automatically. If this is the first time using Unity, the Unity – Project Wizard dialog will appear.

If you are working with multiple Unity projects, you may want to show the Project Wizard every time you open the Unity Editor. To change this behavior, choose Edit -> Preferences… from the main menu.

Unity - Editor Preferences

Unity – Editor Preferences

Check the “Always Show Project Wizard” option to show the Project Wizard when you open the Unity Editor instead of automatically opening the previously opened project.

If the Project Wizard dialog did not appear, select File -> New Project… from the main menu.

Select the “Create New Project” tab.

Unity - Project Wizard

Unity – Project Wizard

Choose a location for your project. This will become the root directory for your project.

Select any standard packages that you want to include in your project. If you have a pro license, you may see more packages marked (Pro Only). You can include these packages in your project but some of the features used in those packages will be unavailable to people using the free version of Unity.

Don’t worry if you don’t select any of the standard packages when you create your new project. You will be able to add any of the standard packages to your project at any time by selecting Assets -> Import Package from the main menu.

Click the Create button to create a new project.

Your new project should appear in the Unity editor with an untitled scene. There should be only the Main Camera GameObject in your scene.

Unity - New Project

Unity – New Project

Adding Some Content

For this tutorial, we’ll just add a rotating cube to the scene. I will introduce more complicated topics in later articles.

Select GameObject -> Create Other -> Cube from the main menu.

Unity - Create Cube

Unity – Create Cube

A new GameObject with the name “Cube” will be created in the center of the view.

Unity - New Cube

Unity – New Cube

We also want to make sure the Main Camera GameObject is aiming at the Cube. To do this, select the “Main Camera” GameObject and position and rotate it so that it is pointing at the Cube.

This can be done quickly by selecting the Cube GameObject in either the Scene or the Hierarchy views and pressing the “F” (focus view) key on the keyboard while the mouse cursor is in the Scene view. With the Scene view now focused on the cube, select the Main Camera in the Hierarchy view and select “GameObject -> Align With View (Ctrl+Shift+F)” from the main menu.

You should see something similar to what is shown below.

Unity - Focus Cube

Unity – Focus Cube

If you play the game now by pressing the “Play” button, you will see a pretty boring silhouette of a cube. Maybe it will look better with a little bit of lighting?

Adding a Light

Let’s add a light to the scene so we can see that our cube has some depth.

Select either “GameObject -> Create Other -> Directional Light” from the main menu or use the “Create -> Directional Light” drop-down box in the Hierarchy view to create a new GameObject with a directional Light component.

Unity - Scene with Directional Light

Unity – Scene with Directional Light

Parenting GameObjects

The position of a directional light doesn’t have any influence on how a object is lit but its direction is important. I want to have the light always pointing in the same direction as the Main Camera so that whatever it is I’m looking at will be lit consistently across it’s faces and I’ll never look at the dark side of the object.

In the Hierarchy view, use the mouse button to (left-)click and drag the Directional Light GameObject and drop it on top of the Main Camera GameObject.

Unity - Parenting Game Objects

Unity – Parenting Game Objects

Doing this will cause the Directional Light GameObject to inherit its position and orientation to be relative to the Main Camera GameObject.

You may notice, that parenting a GameObject to another does not change its position or orientation in the scene view. Unity will modify the parented GameObject’s local position and orientation so that it remains in it’s initial position. However, if we move the Main Camera GameObject, the Directional Light will be moved along with it.

Parenting one GameObject to another is good way to group many GameObjects together that have a commonality. It is not uncommon to create an empty GameObject (a GameObject with no Components) where its only purpose is to act as a parent to all the GameObjects in a group.

Since we want the Directional Light to always point in the same direction as the Main Camera and we’ve parented the light to the camera, we can simply set the Directional Light‘s local position and orientation to 0.

Select the Directional Light in the Hierarchy view and set its X, Y, and Z Position properties to 0 and its X, Y, Z Rotation properties to 0. Leave the X, Y, and Z Scale properties at 1.

Unity - Directional Light (Zero Transforms)

Unity – Directional Light (Zero Transforms)

To confirm that the light is pointing in the same direction as the Main Camera, select the Main Camera GameObject from the Hierarchy view and press the “F” (focus view) key while the mouse cursor is over the Scene view. The Scene view should zoom out so that both the Main Camera and the Directional Light are in view. Use the Alt+LMB combination to rotate the Scene view.

Unity - Directional Light Aligned to Main Camera

Unity – Directional Light Aligned to Main Camera

As you can see from the image, the light rays coming from the Directional Light GameObject are pointing in the same direction as the Main Camera.

Pressing “Play” now should show a cube that is lit by the directional light.

Make it Spin

Now let’s add some action! We’re going to make the cube spin slowly.

In the Project view, create a new folder called Scripts (Either right-click in the Project view and select Create -> Folder from the pop-up menu that appears, or select “Folder” from the Create drop-down menu at the top of the Project view). Rename the new folder to “Scripts” by (single) left-clicking on the new folder in the Project view or press “F2” on the keyboard while the new folder is selected in the Project view.

Right-click on the Scripts folder and select “Create -> JavaScript” from the pop-up menu that appears.

Rename the new JavaScript file to “Rotation“.

If you now open Windows Explorer and navigate to the folder where your project exists, you will notice that the Assets folder mirrors the file structure of the Project view. The Project view is the same as the files contained in the Asset folder in your project’s root folder. Any changes made to files in the Project view will be directly reflected on your computers file system.

Open the JavaScript asset in the script editor by double-clicking on the Script asset in the Project view. (Unity comes with the MonoDevelop editor for editing script assets).

Unity - MonoDevelop

Unity – MonoDevelop

Copy-Paste the following code into the Rotation.js file.

#pragma strict

function Update () {
	transform.Rotate( Vector3.up * ( 90 * Time.deltaTime ) ); 
}

Save the file and return to the Unity Editor.

Now drag and drop the Rotation script asset from the Project view onto the Cube GameObject in the Hierarchy view. Unity will automatically create a Script component on the Cube GameObject and assign the Rotation script asset as the script source for the component.

You should see something similar to what is shown in the image below.

Unity - My Cube

Unity – My Cube

Notice in the Inspector view that the Cube GameObject now has the Rotation script component assigned to it.

If you play the game now, you should see something similar to what is shown below.

Adding Your Projects to Version Control

In this section I will discuss how to add your Unity project to a version control system (VCS). This is an optional step and is only required if you will be working together on the same project with other people or if you just want to save your project files in a version control repository for safe keeping.

I will not explain how to use the VCS. Whether you use Subversion, Git, Perforce, SourceSafe is not really important but knowing how to convert your project to use a Version Control System and what files need to be added to the VCS is important.

Enable Meta File Mode

The Unity Editor keeps track of the Assets (files) and the Asset import settings in the Asset database file. The asset database file is stored in the Library folder of the project Root. It is generally not a good idea to distribute this file together with your project because the format of the file is platform specific (it may not be able to be opened properly on other OS’s other than the one it was created on).

To solve this problem, you can specify that you want to generate Meta Files for every single file, and directory in your project’s Asset folder.

To turn on Meta File Mode for your project, select “Edit -> Project Settings -> Editor” from the main menu.

Unity - Edit Project Settings

Unity – Edit Project Settings

The Editor Settings will open in the Inspector view.

Unity - Enable Meta Files

Unity – Enable Meta Files

Select “Meta Files” in the Version Control Mode drop-down menu.

This will create a “.meta” file for every file and folder in your project’s Asset folder.

It is extremely important that if you copy/rename/move or delete a file or directory anywhere in the Assets folder that you also copy/rename/move or delete the .meta file with the same name. Failing to do this will break your project and all of your team members will become very angry with you!

Adding to Version Control

Once you have enabled Meta File Mode on your project then you need to add the following folders to your version control system:

  • Assets: Add the Assets folder and every single file and corresponding .meta file in the Assets folder into your version control system.
  • ProjectSettings: Add the ProjectSettings folder and all of its contents to your version control system.

With the .meta files in place, Unity can rebuild the asset database and automatically re-import all of the raw assets in the Assets folder without losing references to files.

You do not need to commit the .sln (Visual Studio Solution files) or the .unityproj (MonoDevelop project files) as Unity is capable of regenerating these files based on the content of your Assets folder.

More Information

As a beginner, it may be difficult to get started with Unity because there is just so much to learn and there is so much information to absorb, you may not know where to begin. The Unity website http://unity3d.com contains several links on the header but you will most likely want to see the documentation.

The main resource for Unity documentation is http://unity3d.com/support/documentation/.

For a beginner, I recommend you first read the Basics: http://docs.unity3d.com/Documentation/Manual/UnityBasics.html.

With a good understanding of the basics, I recommend you watch a few video tutorials here: http://unity3d.com/support/documentation/video/ and then work through a few of the larger tutorials here: http://unity3d.com/support/resources/tutorials/

While you are working on your projects, you will very often refer to the Unity Manual http://docs.unity3d.com/Documentation/Manual/index.html, the Reference Manual http://docs.unity3d.com/Documentation/Components/index.html and the Scripting Reference http://docs.unity3d.com/Documentation/ScriptReference/index.html.

These three resources (User Manual, Component Reference, and Scripting Reference) are also installed on your computer locally when you install Unity and are accessible from within the editor using the Help menu.

Additionally, you can click the Component Reference (Component Reference) button on any component in the Inspector view to go to that component’s reference documentation.

I wish you the best of luck creating that next block-buster title!

5 thoughts on “Introduction to Unity 3.5

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>