Unity3D Tutorial

Jeb Palveas and Jack Chang, July 2012.

    Introduction

    These tutorials were designed to be a simple as possible to get you familiar with the unity development environment. For more advanced stuff check the resources that are provided or find your own. There are thousands!

    Before doing these tutorials it is highly recommended that you watch the following video tutorials. They cover most of the stuff that will be covered below and are very easy to follow. After watching these videos the tutorials will become very simple and straightforward.

 

http://www.unity3dstudent.com/category/modules/essential-skills/

http://www.unity3dstudent.com/category/modules/beginner/

http://www.unity3dstudent.com/category/modules/intermediate/

 

     Tutorial 1: Unity Development Environment Basics

     Goal: To orient yourself with the Unity’s development environment and understand the basic function/purpose of each window.

 

     Additional Resources: http://unity3d.com/support/documentation/Manual/Learning%20the%20Interface.html

 

     Panels:

     Project Panel

     Contains the resources or assets of the project. Can include items such as: Unity project files, textures, scripts and meshes.

     It is basically the asset folder of your project.(If you look at both side by side they should match one to one.

     Hierarchy Panel

     Displays a hierarchical list of game objects within the current scene.

     Inspector Panel

     Displays the currently selected object’s/file’s components or properties.

     Contains a preview window for viewing textures or meshes.

     Can also view script code.

     Game Panel

     Is a preview of your current scene. Can be run to see the project in action.

     Scene Panel

     Displays the game objects placed within the current scene and corresponds to the hierarchy.

     Provides GUI manipulation of objects within the scene.

 

(Tip) Try changing the persp. of scene panel and becoming familiar with QWER, Alt and Shift keyboard shortcuts

 

 

     Tutorial 2: The Initial Camera Game Object + A Cube

     Goal: To understand the basic workflow in the development environment

     Source: here is the source to the scene for this tutorial.

 

     In order to be viewable every scene needs a camera. By default, Unity provides you with initial main camera object. It has its transform component, camera properties, as well as other components. It can be manipulated via the scene panel inspector or by scripts.

 

     Exercise 2.1: Adding a cube to the scene and viewing it:

     Add cube to the scene by clicking GameObject > Create Other > Cube Translate the cube to position (0,0,0) by the scene or inspector

     Position the camera so the cube is visible. Change camera transform via Inspector ( Position, Rotation, Scale)

     Preview the game and observe the cube

 

While this may be very trivial and can be done in less than 10 seconds it is important to note what happened. When adding the cube gameobject it showed not only the scene but the hierarchy tab as well. This is because the tab hierarchy lists all the game objects that make up your current scene. Additionally, notice that both the camera and cube gameobject come with a default transform component as well as various other components.

 

     Important: Changes made while the play/preview mode is active will not save once it stops previewing. Make sure you are not previewing the scene when you want to save the modifications you are making.

 

     Tutorial 3 - Scripting Basics

     Goal: To familiarize yourself with scripting fundamentals

     Additional Resources:

Using Scripts

Getting a script to run without attaching it to a GameObject

 

     Exercise 3.1: Hello World Script (here is the source to this scene)

     Create a script Assets >  Create > JavaScript 

     Name the script “HelloWorld”.

     Click the script and in the inspector panel type the following code into the start and update function

var counter : int;

 

function Start ()

{

       Debug.Log("Hello World.");

       counter = 0;

}

 

function Update ()

{

       counter ++;

       Debug.Log(counter);

}

 

     Create an empty gameobject GameObject > Create Empty

     Drag the script to the empty gameobject in the hierarchy to add it as a component

     Run and view the results

 

     Exercise 3.2: Reusable Scripts (here is the source to this scene)

     Add cube to the scene by clicking GameObject > Create Other > Cube

     Position the cube so it is viewable with the camera

     Create a script Assets >  Create > JavaScript

     Name the script “Mover”.

     Insert the following code into the start and update function

var MAX_X : int = 5;

var MIN_X : int = -5;

var X_Increment : float = 0.1;

var Dir_Right : boolean = true;

 

function Start ()

{

       Debug.Log("Mover Starts");

}

 

function Update ()

{

       if(Dir_Right)

              transform.position.x += X_Increment;

       else

              transform.position.x -= X_Increment;

             

       if(transform.position.x >= MAX_X)

              Dir_Right = false;

       else if(transform.position.x <= MIN_X)

              Dir_Right = true;

}

 

     Assign the script to the cube and the camera by dragging it to the objects within the hierarchy

     Run and view the results

 

     Exercise 3.2(Script Version): Reusable Scripts (Source to this scene)

     Create a script Assets >  Create > JavaScript 

     Name the script “CreateCube”.

     Insert the following code

function Start ()

{

    Debug.Log("Create Cube Starts");

      

    var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);

    cube.transform.position = Vector3 (0, 0, 0);

    cube.AddComponent("Mover");

   

    //for the camera

    Camera.main.gameObject.AddComponent("Mover");

    Debug.Log("Added the Mover script to the camera");

   

}

 

     Assign the script to the camera by dragging it to the object

     Create a script Assets >  Create > JavaScript 

     Name the script “Mover”.

     Insert the following code

var MAX_X : int = 5;

var MIN_X : int = -5;

var X_Increment : float = 0.1;

var Dir_Right : boolean = true;

 

function Start ()

{

       Debug.Log("Mover Starts");

}

 

function Update ()

{

       if(Dir_Right)

              transform.position.x += X_Increment;

       else

              transform.position.x -= X_Increment;

             

       if(transform.position.x >= MAX_X)

              Dir_Right = false;

       else if(transform.position.x <= MIN_X)

              Dir_Right = true;

}

 

     Run and view the results

 

     Tutorial 4: Occluder and Collision Basics

     Goal: Learn how to add and manipulate components

     Exercise 4.1: Simple components (source to this scene)

     Create a floor by adding a plane object to the scene and naming it “Floor” GameObject > Create Other > Plane

     Create a cube above the floor object and rotate the cube slightly(make sure it is viewable via the camera) and name it “GravityCube” GameObject > Create Other > Cube

     Add a light to the scene GameObject > Create Other > Point Light

     Add a gravity component to the cube by selecting the gravity cube and Component > Physics > Rigidbody

     Extra: Change the Material type of the box collider by importing the Physics Materials package under assets

     Create and add a script to the cube that changes its color on a collision event

var theColor : Color;

var theOtherColor : Color;

 

function Start(){

       theColor.r = 0;

       theColor.g = 10;

       theColor.b = 10;

      

       theOtherColor.r = 10;

       theOtherColor.g = 0;

       theOtherColor.b = 10;

}

 

function OnCollisionEnter(){

       Debug.Log("Collided!");

       if(renderer.material.color == theColor)

              renderer.material.color = theOtherColor;

       else

              renderer.material.color = theColor;

 

}

 

     Run and view the results

     Exercise 4.1(ScriptVersion): (source to this scene)

     Do the following by adding the script below to the default camera.

     Creates a floor

     Creates cubes above the floor object and rotate the cube slightly

     Adds a gravity component to the cubes and gives them some bounciness

function Start ()

{

       var floor = GameObject.CreatePrimitive(PrimitiveType.Plane);

       floor.transform.position = Vector3(0,-1,10);

       floor.transform.localScale =Vector3(10,1,10);;

      

       var cube1 = GameObject.CreatePrimitive(PrimitiveType.Cube);

       cube1.transform.position = Vector3(0,10,10);

       cube1.transform.rotation = Quaternion.Euler(10,0,10);

       cube1.AddComponent("CollisionColor");

       cube1.AddComponent("Rigidbody");

       cube1.collider.material.bounciness = 1.5;

      

       var cube2 = GameObject.CreatePrimitive(PrimitiveType.Cube);

       cube2.transform.position = Vector3(2,10,10);

       cube2.AddComponent("CollisionColor");

       cube2.AddComponent("Rigidbody");

       cube2.collider.material.bounciness = 0;

}

     Create and add a script to the cube that changes its color on a collision event

var theColor : Color;

var theOtherColor : Color;

 

function Start(){

       theColor.r = 0;

       theColor.g = 10;

       theColor.b = 10;

      

       theOtherColor.r = 10;

       theOtherColor.g = 0;

       theOtherColor.b = 10;

}

 

function OnCollisionEnter(){

       Debug.Log("Collided!");

       if(renderer.material.color == theColor)

              renderer.material.color = theOtherColor;

       else

              renderer.material.color = theColor;

 

}

     Run and view the results

 

     Tutorial 5: Prefabs

     References:

     http://www.unity3dstudent.com/2010/07/beginner-b03-prefabs/

     http://docs.unity3d.com/Documentation/Manual/Prefabs.html

     http://cgcookie.com/unity/2011/12/27/introduction-to-prefabs/

     Goal: To understand and be able to utilize prefabs

     Exercise 1: Create a simple prefab (source to this scene)

     Create a floor by adding a plane object to the scene

     Create a prefab by Assets > Create > Prefab

     Name it CollisionCube

     Add a cube to the prefab by selecting the prefab and creating a cube

     Add a gravity component to the prefab

     Create and add a script to the prefab that changes its color on a collision event

     Create several CollisionCubes above the floor object and rotate the cube slightly(make sure it is viewable via the camera)

     Make sure to assign the prefab to the variables in the  Create Environment script

     Run and view the results

 

     Tutorial 6: Cameras

     Goal: To understand and be able to utilize multiple cameras by switching between cameras and attaching cameras to objects

     Tutorials/References:

     http://docs.unity3d.com/Documentation/Manual/Cameras.html

     http://www.unity3dstudent.com/2010/07/essentials-e09-cameras/

     http://www.youtube.com/watch?v=Xr7t9TyM3A0&feature=player_embedded

     Tutorial 7: Lights

     Goal: To understand and be able to utilize multiple lights within unity (point/directional/spotlight)

     References:

     http://docs.unity3d.com/Documentation/Manual/Lights.html

     http://www.unity3dstudent.com/2010/07/essentials-e08-lights/

 

     Tutorial 8: Particles

     Goal: To understand how unity uses/handles particles

     References:

     http://docs.unity3d.com/Documentation/Manual/ParticleSystems.html

     http://www.unity3dstudent.com/2010/10/beginner-b23-particle-systems/

     http://cgcookie.com/unity/2012/02/13/unity-particles-getting-started-with-particles/

 

     Tutorial 9: Menus/HUD

     Goal: To understand and be able to utilize unity’s GUI textures

     Tutorials/References:

     http://docs.unity3d.com/Documentation/Components/GUIScriptingGuide.html

     http://www.unity3dstudent.com/2010/07/beginner-b16-switching-scenes/

     http://www.unity3dstudent.com/2010/10/beginner-b25-gui-texture-and-mouse-events/

 

     Tutorial 10: Meshes/Models/Animation

     Goal: To understand and be able to utilize models/animation within unity

     Process: There are many ways to model and animate characters for games but it essentially boils down into 3 parts.

i       Modeling the Character: Modeling the character involves the creation of the characters mesh and textures. This is generally achieved with modeling software such as Blender or Maya

ii      Rigging the Model: Rigging the model is the process of giving the character a skeleton or armature which allows us to control the characters mesh. This can be done in blender or other software.

iii    Animating the Model: Animating the model involves applying the animation to the characters skeleton. This can be achieved via keyframe animation or using pre-made .bvh animation files. Keyframe and binding .bvh animation can be done in Blender or other software such as MotionBuilder or WebAnimate.

 

     Free Assets:

     http://www.blendswap.com/ - Good source for many types of assets

     http://mocap.cs.cmu.edu/ - tons of .bvh animation files that need to be bound to a model

 

     Blender - Modeling/Rigging/Animation

     http://www.blender.org/

     Getting Started

     http://cgcookie.com/blender/category/getting-started/

     Tutorials - Modeling and Rigging http://cgcookie.com/blender/2010/05/13/game-enginecharacter-part-1/

http://www.youtube.com/watch?v=_0JgoVx30eM&feature=related

 

     MotionBuilder - Animation/Binding (nearly all of AutoDesk’s software is free for students including Maya and 3DSMax)

     www.motionbuilder.com/

     Tutorials - Binding .bvh files to your Model

     MotionBuilder Speed Tutorial (Basic Part1) Importing free .bvh Mocap data

     MotionBuilder Speed Tutorial (Basic Part2) Importing Multiple free .bvh Mocap data

     MotionBuilder Speed Tutorial (Basic Part3) .bvh applied to MB Control Rig

     MotionBuilder Speed Tutorial (Basic Part4) Applying free .bvh Mocap data to a 3D Character

     MotionBuilder Speed Tutorial: How to remove the translation of a Characters Motion (In-Place Mode)

     Mobu Video Game Tutorials: Looping Run Cycle Using Anim Layers(Part1)

           

 

     WebAnimate - Animation/Binding

     http://www.ikinema.com/webanimate/webanimate.php#

     Tutorials - Binding .bvh files to your Model http://www.youtube.com/watch?v=HfqvO6jQ5dU&feature=youtu.be

http://www.youtube.com/watch?v=AYFgiseVKAs

 

     Optional Kinect Motion Capture - You can generate your own animation .bvh files via free Kinect software.

     http://www.brekel.com/?page_id=155

     http://area.autodesk.com/blogs/louis/3ds_max_and_motion_builder_workflow_and_a_bit_of_kinect - Part  5 video

 

 

 

 

 

 

 

 

 

EXTRA

 

References & Resources

http://www.unity3dstudent.com/category/modules/essential-skills/

http://www.unity3dstudent.com/category/modules/beginner/

http://www.unity3dstudent.com/category/modules/intermediate/

http://unity3d.com/support/documentation/Manual/Unity%20Basics.html

http://www.youtube.com/playlist?list=PL568B13BBC149DB3C&feature=plcp

http://walkerboystudio.com/html/unity_training___free__.html

http://davedub.co.uk/bvhacker/index.html

http://cgcookie.com/unity/category/tutorials/

 

Terrain

http://www.youtube.com/watch?v=wnjff1q_SZk