A Unity Primer

For anyone interested here's a Unity Primer that will help anyone brand new to Unity get oriented.

It's in the form of a tutorial; go ahead and follow along in Unity for best results.

New Project Setup

Open Unity and then go to File > New Project..., select the "Create New Project" tab if necessary, and then enter the folder name for the new project.

Next select Edit > Project Settings > Editor and change "Version Control" to say "Visible Meta Files".

Assuming you're using a Git repo, add all the following to a ".gitignore" file in your repo base folder (adapted from http://stackoverflow.com/questions/18225126/how-to-use-git-for-unity3d-source-control ):

# .gitignore for Unity Projects

# Unity generated
Temp/
Library/

# Visual Studio / MonoDevelop / Vim generated
ExportedObj/
obj/
*.svd
*.userprefs
/*.csproj
*.pidb
*.suo
/*.sln
*.user
*.unityproj
*.booproj
*.swp

# OS generated
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

Folder Structure

Unity doesn't have a main project file. Instead it consists of a group of independent assets and objects that all work together to make a game. You can recognize Unity project folders because they'll contain Assets/ and ProjectSettings/ folders at least.

Assets/ contains all of your game's images, sounds, 3D models, scripts, and so on. You can organize it into subfolders as you like. There are a few special subfolder names that are automatically treated differently. For example, any editor plug-ins you have (that hook into the actual IDE) are stored locally in your project in the Assets/Editor folder and aren't compiled as part of your actual game. Here's a full list - the only other special folder I know you'll have to mess with eventually is the Plugins folder:http://wiki.unity3d.com/index.php/Special_Folder_Names_in_your_Assets_Folder

When you download any assets you've bought on the Unity Asset store, those assets are imported directly into your current project. Even sample projects! For example, if you want to check out this free Unity sample project: https://www.assetstore.unity3d.com/en/#!/content/11228, just create a blank Unity project, visit the that link, and then click "Open in Unity". All the assets will be imported into your new blank project and you'll be able to play it.

When you create a new project you'll have a list of optional packages to import (with check boxes next to each). The editor plug-ins and such that you download from the Asset Store become available on this list in addition to being imported into your current project, which makes them easy to include in future projects.

Just having assets in the folder doesn't take up any space in your game code unless you actually use them in your scenes. Likewise assets will often be adapted or converted to be appropriate for a particular platform on the fly without changing the original assets. So it's safe to have unused assets hanging out in the asset folder.

Scenes

A scene is a collection of objects, scripts, assets, etc. Unity automatically loads and unloads assets appropriately when switching scenes.

Rather than imperatively drawing its scenes like Plasmacore, Unity models its scenes with a hierarchy of GameObjects and then automatically draws everything based on game object properties. So drawing your game becomes a matter of updating an object hierarchy - creating and destroying objects, making sure that they're positioned correctly and assigned the right texture, etc.

A new project starts with a new Scene being edited that's not saved yet. If you hit Command+S right away, the Save Scene dialog will come up and you can enter a name for it. The scene will then appear in the Project > Assets panel that's at the bottom of the screen by default. You can then create new scenes and switch between them there.

Hierarchy and Empty Game Object

By default the left side of the editor is the Hierarchy panel. That shows you the tree (in list form) of all the objects in the scene. Go to the menu and pick GameObject > Create Empty and an "empty" game object called "GameObject" will be added to the hierarchy.

Click on the empty GameObject in the Hierarchy. In the Inspector panel (right side by default) you'll see all the properties of that GameObject. Every GameObject has a "Transform" (its position, orientation, and scale in 3D space) and CAN have many other things ("components") like a texture, a sound effect, or a script added to it.

Let's turn this empty game object into a cube with a textured image on each side.

Meshes

With the empty GameObject selected in the list, click "Add Component" on the Inspector panel. You'll see the categories of components you can add. Pick Mesh > Mesh Filter. A mesh is an untextured 3D model (basically a bunch of triangles) and a Mesh Filter is the class that links a Mesh to a GameObject.

The Mesh Filter starts out with a Mesh of "(none)". Click the little circle to the right of that box and you can pick one of several mesh primitives to use. Select Cube.

Nothing shows up yet. Meshes can be used for different purposes - for instance you might want to have an invisible mesh for collision checks. For now click Add Component again and choose Mesh > Mesh Renderer - this is a component that automatically renders whatever Mesh is attached to the game object. It's bright magenta by default because we haven't defined a material yet.

Textures and Materials

We don't assign textures directly to Mesh Renderers. Instead we create a Material that has a texture and assign the material.

Take an image from anywhere on your computer and drag it into the Assets panel. Then right-click in the panel and say Create > Material. With the material selected, drag the image asset onto the box in the Inspector panel that says "None (Texture)". Your material now uses that texture.

Now click on your game object in the Hierarchy. Expand the Mesh Renderer > Materials subtree in the Inspector panel and drag your new Material up from the Assets panel to the Materials box labeled "Element 0 / None (Material)". You now have a textured cube!

Prefabs

If you want multiple copies of that textured cube in various scenes you don't have to go through all those steps each time. A prefab is a game object with preset components and properties. In the Assets panel right-click and select Create > Prefab and name it. It's "empty" right now, so pick your GameObject from your Heirarchy and drag it on top of the new prefab in the Assets panel. The prefab will turn from white to blue indicating that it's defined. Now you can drag out any number of copies of that prefab from Assets into the Scene and they'll all be textured cubes!

One cool trick with prefabs is that you can change all instances by changing the prefab. You can drag a different texture into the prefab and it will intelligently replace the original texture - or you can drag a whole new game object into it and all instances of the prefab will be updated to use that new game object definition!

If you select the menu option GameObject > Create Other you will see a bunch of options like Cube and Sphere. Those are essentially just prefabs that are a little more convenient than the steps we took.

Cameras

Each scene can have multiple cameras. Each camera draws what it sees to the screen in an order determined by the "Depth" property of the camera. Each game object has a "Layer" it belongs to - and you can add custom layers - and each camera can selectively draw certain layers via its "Culling Mask" setting.

Just to give you an idea of what's possible: if you wanted a bitmap image always be drawn behind all 3D objects, you could create two cameras, a Quad GameObject with the image material on it (note that quads are invisible from one side and visible from the other) and set to its own layer, position one camera so that the image fills the view, set the culling masks so that one camera draws only the background layer and the other draws everything else.

For now, move your textured cube into the middle of the scene view, select the Main Camera object, and select Game Object > Align With View from the top menu to have the camera match your current viewpoint. Then press the Play button at top to view the scene and Play again to stop it.

It's pretty dark with no light in there so could add a directional light and play with that if you wanted.

Scripts

Scripts are components you can attach to game objects. Right click in the Assets panel and select Create > C# Script. Drag it on top of either the cube game object in the Hierarchy panel, or select the game object first and drag the script asset onto a blank area of the Inspector panel.

Double-click the script to edit it in the MonoDevelop editor that comes with Unity. Add the lines indicated below to the starter code that's there already:

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

    public float x_angle;  // ADD THIS
    float y_angle = 90;  // ADD THIS

    // Use this for initialization
    void Start ()
    {        
    }
    
    // Update is called once per frame
    void Update () 
    {
        // ADD the following
        float dt = Time.deltaTime;
        transform.Rotate( new Vector3(x_angle*dt,y_angle*dt,0) );
    }
}

Be sure and save the script (Command+S) and press Play. You'll see the cube spinning on one axis.

Stop the project again, click on the cube object, and look at the Inspector. In the Script component you'll see a box for "x_angle" where you can enter a value. This is a really neat feature of Unity - any "public" properties are visible in the Editor for tweaking!

In the script you can reference "this.transform" (or just "transform") to get the transform object of the game object the script is associated with, "this.GetComponent<MeshFilter>()" to get the first mesh filter component of the associated game object (could be null), etc.

Nested Game Objects

The last thing I'll mention is the idea of nesting game objects. In the Hierarchy list you can drag any object into any other object. Child objects are positioned relative to their parent, so you could place a bunch of objects in a "boat" object and then all the objects would move with and be drawn with the boat automatically. And often times it's convenient to put several objects in an empty game object (as a container), move the container around, and then programmatically show or hide child objects to achieve various effects.

That should be enough info to get started!