Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Unity3D Tutorial - Beginner Basics

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Unity3D Tutorial - Beginner Basics

0. About This Tutorial


1 Unity3D is a Game Development tool for Windows and Mac OS. This tutorial will help a beginner
Unity3D basics, using a Windows PC, a mouse, and keyboard.
2 To run Unity3D well, a Windows computer needs a 3D graphics card, and 2GB or more of RAM.
3 To understand this tutorial, you must be comfortable running computer programs in Windows, and using
a mouse and keyboard. Knowing programming is not required.
4 By the end of this tutorial, a beginner should be able to make and play a simple Scene in Unity3D, with
a First-Person Controller, and simple obstacles. More advanced users might be able to create a
platform-based 3D maze game, complete with win condition.
5 This tutorial will hopefully teach enough to make a beginner feel comfortable with Unity3D.

1. Installing Unity3D
1 Head to http://unity3d.com/unity/download and download the Unity3D
installer for free! It's a large file so be patient! Run it after it downloads.
2 While downloading, make sure you have an e-mail account. You need it to finish installation!

3 After the installer verifies itself, press , then to


the license, which says you can't use the free version if you make more
than $100,000 a year (note: I am not a lawyer, this is not legal advice).
4 For slow computers, un-check to reduce the install, and speed up the first load time.
5 Press , , and wait for the progress bar .
6 Finally, after Unity finishes installing press .
7 Unity3D should start up on it's own. If it doesn't start automatically, start Unity3D with the shortcut that
might be on the desktop, or by find it in the Start-menu or the Windows dashboard.
8 A special set of windows will pop up when you start Unity3D the first time. For the free version, you
need to , and press . Give your Name, Email, create
a Password, and mark . Agreeing to the Terms of
Use means that you're 13 or older, won't do anything illegal with Unity, won't hack Unity in any way,
and will respect copyright (again, I am not a lawyer, this is not legal advice).
9 Press to continue. After creating your account, check your e-mail and .
10 Register the installation with the Email and Password you entered earlier, then press .
You can skip the survey with at the bottom, and finally !

2. Start a Project (in Windows)


1 If you un-checked earlier, just select the tab. Otherwise, after the
Example Project finishes loading, press , and select .
2 to the , and create a (Right-Mouse Button in the File
Chooser and select , or just press Ctrl + Shift +N)
3 Name the folder , then . Press to create the project.
3. Pick a User Interface Layout
1 Choose a User Interface layout using the drop-down menu ( ) on the upper-right.
2 Below is an example of the Tall User Interface (or UI for short):

3 Make sure you can find , , , and .


4 If you lose any UI, check , or reset the layout with the drop-down menu.

4. Use the Scene User Interface


1 Find your User Interface. It looks something like this:
The User Interface is used
while play-testing your game. If you
accidentally click into that UI, just Click on
again.
You can toggle (turn on and off) the grid

plane with . The grid on can help with


a sense of distance and scale while editing.

2 Turn the camera by holding the Right-Mouse Button and moving the mouse. Turning
with the mouse like this is called Mouselook.
3 While holding the Right-Mouse Button, move the camera in the using W, A, S, and D.
If you have ever played Minecraft, or another First Person Shooter on a PC, this should be easy.
4 Notice the 3D Scene Gizmo at the Upper Right of the . You'll notice it move
when you Mouselook. It's diagramming the XYZ Axis.
You can imagine the XYZ Axis in real life using a hand gesture, like this:
The Z axis (Depth) is forward, along your pointer finger
The Y axis (Height) is up, along your thumb
The X axis (Width) is to the side, along your middle finger
If you've studied Algebra or Geometry, you might have seen an XY Grid, also called a
Cartesian Plane. The XYZ Axis is like that, but with a Z dimension too!
If you Click on the cube in the center of the 3D Scene Gizmo, you will
toggle how the camera draws 3D, between Perspective and Isometric.
Perspective is how we see in real life.
Isometric is helpful for lining up objects that are far away.

5 The will help you organize your game, in 3D space.

5. Use the Hierarchy User Interface


1 The will help you organize your game as a list of Game Objects.
Everything currently in the game Scene will be listed here!
You can add a new element to the game with .
Quickly Double-Click on an element in the and the
will adjust to show it to you.
Slowly Double-Click on an element in the and you
can rename it!

2 Press and select . It should appear in the , and the .


3 If you cannot see the new Cube, double-click on its name in the .
4 Create a with and .
5 Don't be afraid to experiment by creating other Game Objects. You can Undo (Ctrl + Z) almost
anything, including adding a new object. To Delete an extra object, select it and press Delete, or press
the Right-Mouse Button over the object in the and select from the menu.
6 You can also find the same create menu through , .
7 Move around the scene using WASD and Mouselook, to see where the
Cube and Point Light are in relation to each other.

8 If you don't see the Translate Gizmo (as pictured to the right), press ,
in the upper-left of the Unity3D UI.
9 Move the Cube and Point Light closer together with the Translate Gizmo
(colored Arrows and Planes in the ). Drag the Arrows with
your mouse, or Drag the Planes between the lines of the arrows.
10 The Cube should light differently in the as the Point Light
moves. If not, press , at the top of the , to toggle lights.
6. Use the Inspector User Interface
1 Select an object in the or and you'll see its details in the .
You can rename an object with the text field at the top.
Hide this object if you un-check next to the name.
All Game Objects have a , which can be
changed with the text boxes. The Transform consists of:
Position in XYZ space
Rotation, which is how it is turned, on the XYZ axis
Scale, which is how it is stretched across the XYZ axis
You can also use other Gizmos and the mouse to change the

Position , Rotation , and Scale . The buttons


that enable those Gizmos are at the top-left of the Unity User
Interface, in a panel that looks like .

You might see these Components somewhere in your scene:


: makes the cube model, or Mesh
: makes the cube collide-able like a box
: allows Game Object to render (show)
: set a light, with color, brightness, and more
: will render a view to the screen
: allows lens-flares to be rendered
: allows custom GUIs to be rendered
: allows sounds to be heard in-game

2 Select your Cube. You can click on it in the , or in the .


3 Set the Cube's Position to . You can change each number
by selecting the text-box with the number in it, and typing in a new number.
4 Set the Cube's Scale to .
5 Rename your Cube to ground.
6 Double-click on ground in the to auto-adjust the to view it.
7 If you don't have a Point Light, create one. Set your Point Light's Position to
.
Select the Main Camera to see Camera Preview in the .
Move around in the with WASD and Mouselook (while holding the
Right-Mouse Button), then with the Main Camera still selected, from the
menu, select , or just press Ctrl + Shift + F.
You should notice the Camera Preview, and the changed.
This (Ctrl + Shift + F) can change any selected .
7. Use the Project User Interface
is a list of Assets (Game Objects, pictures, sound,
scripts, ...) that could be in your . It's different from
the , which is a list of Game Objects that are in your
.
You can Import new assets with the menu item.
The Assets folder in mirrors the actual file system!
To see it in Windows Explorer, press the Right-Mouse Button on
, then .

1 To import a Character Controller from the Standard Assets Library, select the menu, then
and .
2 To keep things simple, just press , and wait for it to load. Or to make the project smaller, un-
check the at the 3rd Person Controller.prefab, and every file within PrototypeCharacter/, including
Constructor.FBX, constructor_done.mat, constructor_diffuse.png, and constructor_normals.png.
3 The folder in now has an arrow . Click the arrow to toggle folder listing.
4 Select the Character Controllers folder, which is inside of the Standard Assets folder.
5 Select the First Person Controller, which looks like a Capsule, which is a rounded Cylinder.
6 Drag-and-drop the First Person Controller into the
There are now 2 Main Cameras in your Game! The Scene started with one,
and the First Person Controller came with one as well!
Delete the Main Camera that was in the Scene first, the one not inside the
First Person Controller. Select it and press Delete, or press the Right-
Mouse Button over the Main Camera and select Delete.
This is not required, but may help with debugging scripts later!

7 Set the Position of the First Person Controller to


8 Rename the First Person Controller to something like player, to help keep things simple for later.
9 Save your Scene by selecting , and (or press Ctrl + S). Name it
something like tutorial, and be sure to save it in the Assets folder, or in a folder inside of it.
10 Save often, especially before you try something new that you have never done before!

8. Play-Test
1 Press the Play button (in the middle, near the top, with one of these buttons )
2 The user interface is now active, and the rest of the UI changed color very slightly.
3 To move the First Person Controller (that was renamed to player), move the mouse (Mouselook), and
use the WASD keys for movement, just like in the . You can use Space Bar to jump!
4 If you fall, you can stop and restart the game by pressing .
5 If your game seems broken, set the player's Position to .
Also, make sure you have a ground cube at Position and
the ground cube's Scale of .
6 While the game is playing, select the player in the , then Click back into the
to give mouse and keyboard focus back to the game. Notice that when you move the
player, the shows the new state of the player's .
7 You can change the details of any Game Object while the game is running with the .
BUT! Any changes you make while in Play Mode can't be saved!
8 You should adjust your Unity settings to more clearly show when the game is running, so you don't
accidentally make changes that can't be saved. Go to , , , and change the

to something obvious. Like, hot pink.


9 Click on the colored rectangle, and select a color using the color chooser.

9. Iterate On Your Game


Iterate means to do something over-and-over again. Game Developers use that word to describe the
working on a game. Most of real Game Development is the same thing over and over:
1 Come up with an idea to try
2 Use tools (like Unity3D) to try it out
3 Test it out, to see if it works like expected
4 If it doesn't work, or there's more to do (almost always there is), go back to the first step!
This is also called the Iterative Process, and it is also similar to the Scientific Method.
Try to add more Game Objects and move them around to create a more interesting Scene:
1 Try to use several cubes and lights to build a maze. You can Scale the cubes into walls, and even
additional ground platforms!
2 Add lighting. Don't be afraid to edit objects in the . Unity can Undo (Ctrl + Z) and Redo
(Ctrl + Y) any of your changes. Also, don't forget to save often (Ctrl + S)!
3 Play-test your game after making some changes, to see if it is more fun!
You could try to make a simple maze, like this (6 Cubes, 2 Point Lights, and a First Person Controller):
To Duplicate a Game
Object, press the
Right-Mouse
Button over it in the
and
select , or
select it and press
Ctrl + D.
For more digital (or
snap-to-grid) control
while adjusting
Game Objects with

the Position ,
Rotation , and
Scale Gizmos,
hold Ctrl, while
Dragging the mouse.
10. Add a Script Component: Restart After Falling
1 To bring the player back to the beginning if the player falls off of a platform, we will need a script.
2 There's a LOT to learn about scripting, which is a way of saying simple programming. During this part
of the tutorial it may be helpful to have someone who knows about programming around to help you!
3 Press the Right-Mouse Button over the Assets folder, in the .
Then select , and . C# is pronounced See Sharp.
4 Name the script Fall, with a capital 'F'. You can also rename it with the Right-Mouse Button menu.
5 Double-click, or press Enter on the Fall
script in the . Then, wait a
minute or two! The script editor,
MonoDevelop, takes some time to load.

6 Add to the Fall script in MonoDevelop, so that it looks like this:


If MonoDevelop opens multiple
times, just close the extra
instances.
Unity3D and MonoDevelop
support several scripting
languages, including:
C#: the strictest option, so it
requires more code, but helps
MonoDevelop offer better
auto-complete. Supports
entire .NET 2.0 library.
JavaScript: UnityScript.
fairly simple syntax, very
close to web JavaScript.
Boo: closely related to
Python. Least common in
Unity communities.

7 The lines with the green next to the line number are the ones you will need to type.
8 Copy this script *exactly*. Every capital letter is capital, and every lowercase letter is lowercase.
9 The curly braces { } are on the keyboard near the Enter key, above and to the right of your right pinky.
10 Save the file in MonoDevelop (with Ctrl + S, or select the menu, then ).
11 You can check to see if your script is correct in Unity by checking the bottom bar:

this example error is a simple case of misspelling: transfrom instead of transform


12 If there is an error, read the error message and use it to help you discover what is wrong, to solve the
problem. This is where having someone who knows about programming will be very helpful!
13 If there are no errors, drag-and-drop the Fall script from the onto
player (which is the renamed First Person Controller).
14 If you did it correctly, you will notice a component in player.
15 If you accidentally added the script more than once, remove extras by pressing the

Right-Mouse Button over the extra script, and select .


16 You can change how the Fall script works by changing Lowest Allowed in the .
17 Test out the script by jumping from your game area! If it does not work, think about what might fix it,
and try it out, or ask a friend to help you Debug your problem. Debugging, or Troubleshooting, which
means fixing computer problems, is a very important and powerful skill for a Game Developer to
develop for themselves. Think of these problems as challenges to improve your skills with!

11. More Scripting Examples


Here are some more scripts you can try to figure out and play with (each script will need its own file):
ClickColor.cs FoundIt.cs
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;

public class ClickColor : MonoBehaviour { public class FoundIt : MonoBehaviour {


Color originalColor; public GameObject player;
public Color color = Color.red; public float distance = 2;
void Start () { public string message = "You Win!";
originalColor = renderer.material.color; public static GameObject FindGObj(System.Type t) {
} object[] f;
void OnMouseDown () { f = UnityEngine.Object.FindObjectsOfType(t);
if(renderer.material.color == originalColor) { if(f != null && f.Length > 0) {
renderer.material.color = color; return ((CharacterController)f[0])
} else { .gameObject;
renderer.material.color = originalColor; }
} return null;
} }
} void Start() {
TouchSensitive.cs if(player == null) {
player = FindGObj(
using UnityEngine; typeof(CharacterController));
using System.Collections; }
// put this on the player }
public class TouchSensitive : MonoBehaviour { void OnGUI() {
void OnControllerColliderHit( if(player == null) {
ControllerColliderHit hit) { print("No player looking for "+name+"!");
Damage dmg = hit.gameObject. Destroy(this);
GetComponent<Damage>(); return;
if(dmg != null) { }
dmg.DoDamage(this.gameObject); float calculatedDistance = Vector3.Distance(
} transform.position,
} player.transform.position);
} if(calculatedDistance < distance) {
Damage.cs GUILayout.Label(message);
using UnityEngine; }
using System.Collections; }
// put this on something that damages the player }
public class Damage : MonoBehaviour {
public void DoDamage(GameObject go) {
Fall f = go.GetComponent<Fall>();
if(f != null) {
go.transform.position =
new Vector3(0, f.lowestAllowed, 0);
}
}
}
These scripts can create color-changing objects, goal objects, and penalty objects that restart the player!
Someone who feels comfortable with Programming may want to check out the Monobehaviour
documentation at http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.html.

12. What Else Can Unity3D Do?


There is still SO MUCH that Unity3D can do to create games! You can use scripting to implement any kind
of gameplay you can think of, but scripting is only one part of it! You should also know about:
Materials, to change the color and texture of objects
Particle Effects, to make explosions water effects, and things that look like magic!
Rigidbody Physics, to allow objects to interact with each other in interesting ways
3D Models and Animations, which you can import from tools like Blender, 3DS Max, or Maya
Music and Sound Effects, which can add a lot to your game
And so much more! Terrain editors, Web and Mobile development, Shaders, Lighting, Novel Game
Controllers, Networking, Graphical User Interface (GUI), the Unity Asset Store,
1 Find the Unity3D User Guide is at: http://docs.unity3d.com/Documentation/Manual/UserGuide.html

You might also like