Introduction to Unity

47
Introduction to Unity For Unity 3.5 Petri Lankoski, [email protected]

description

My teaching materials for introducing Unity. There are related Unity Packages containing prefabs, assets, and scrips used. Updated slides 2013/01/07 to reflect the location of the packages.

Transcript of Introduction to Unity

Page 1: Introduction to Unity

Petri Lankoski, [email protected]

Introduction to UnityFor Unity 3.5

Page 2: Introduction to Unity

Petri Lankoski, [email protected]

New Project File -> New Project…

Set name and directory where you want to store the project

Select Image Effect (ONLY IF

YOU HAVE Pro) Toon Shading

Page 3: Introduction to Unity

Petri Lankoski, [email protected]

Importing a PackageDownload:

If you have free version: http://www.mediafire.com/file/2bdmrn5j4vcikpa/

escape_stripped.unitypackage.zip If you have Pro

http://www.mediafire.com/file/y5i38txo42fj8i3/escape.unitypackage.zip

Unzip the downloaded file

Assets -> Import Package -> Custom Package… Select the downloaded package

Page 4: Introduction to Unity

Petri Lankoski, [email protected]

Anatomy of Unity GUIProject Frame contains assets and scripts• We got these from packages• These are your tools to

build the game

Page 5: Introduction to Unity

Petri Lankoski, [email protected]

Anatomy of Unity GUIScene & Hierarchy views• View to your level (game)• For building a level

Page 6: Introduction to Unity

Petri Lankoski, [email protected]

Building a scene

Delete Main Camera

Page 7: Introduction to Unity

Petri Lankoski, [email protected]

Adding a Plain

Page 8: Introduction to Unity

Petri Lankoski, [email protected]

Anatomy of Unity GUI

Inspector• Shows details of the

selected object

Page 9: Introduction to Unity

Petri Lankoski, [email protected]

Modifying the PlainChange X and Z to 20• Experiment

to find suitable scale

• Y should be 1Drag-and-drop

ground to plain

These should be0

Page 10: Introduction to Unity

Petri Lankoski, [email protected]

Navigating in Unity

Hand tool (shortcut: Q)- click-drag to move camera- ALT click-drag to orbit camera around- CTR click-drag to zoom

Move tool (shortcut: W)

Rotate tool (shortcut: E)

Scale tool (shortcut: R)

On scene view:• F to zoom to selected object• Hold right mouse to enable• ASWD movement• Q up, E down

Play Mode

Page 11: Introduction to Unity

Petri Lankoski, [email protected]

Save a Scene File -> Save Scene

Name it “First” Or something else

Page 12: Introduction to Unity

Petri Lankoski, [email protected]

Player & Light Source

Drag-and-drop Player

Page 13: Introduction to Unity

Petri Lankoski, [email protected]

Directional Light

Move by Drag fromAn arrow

Rotate by Drag fromThe sphere

Page 14: Introduction to Unity

Petri Lankoski, [email protected]

Player PrefabMake sure thatObject is on the plain• Set to

0,0,0

Drag up until the object is totally visible

Page 15: Introduction to Unity

Petri Lankoski, [email protected]

Adding Manager Rename the empty object

as GameManager

Drag-and-drop GameAgents on GameManager

Page 16: Introduction to Unity

Petri Lankoski, [email protected]

Time to Test

Hit Play

Page 17: Introduction to Unity

Petri Lankoski, [email protected]

Adding Waypoints for an Enemy

Drag and drop four Waypoint to scene• Place them to

corners (as in Figure)

• Make sure that Waypoints are on top of the plain

Page 18: Introduction to Unity

Petri Lankoski, [email protected]

Grouping Objects in Hierarchy

Rename waypoints Grouping Object

Page 19: Introduction to Unity

Petri Lankoski, [email protected]

Connecting Waypoints

1. Drag and drop Waypoint2 to NextTarget on Waypoint1

2. Drag and drop Waypoint3 to NextTarget on Waypoint2

3. …

Page 20: Introduction to Unity

Petri Lankoski, [email protected]

Connecting Waypoints

Drag-and-drop Enemy

Page 21: Introduction to Unity

Petri Lankoski, [email protected]

Adding an Enemy

Drag-and-drop Waypoint1 Target (on Enemy)

Page 22: Introduction to Unity

Petri Lankoski, [email protected]

Time to Test

Page 23: Introduction to Unity

Petri Lankoski, [email protected]

Adding Things Walls:

Hierarchy: Create -> Cube

Scale & Rotate & Move

More complex objects are modeled in separate software.

Page 24: Introduction to Unity

Petri Lankoski, [email protected]

New Objects from MayaCreate an object in Maya

Save (ma/mb) Maya needed on the machine running Unity

Export FBX

Move the model to Assets folder

Set import scale Do not use Transform – Scale on Inspector with

imported models to change the default scale

Page 25: Introduction to Unity

Petri Lankoski, [email protected]

New TexturesCreate a texture in Photoshop

Preferred size: n2 x m2

Default max size of a texture: 1024x1024 Bigger textures consumes more memory

Use psd or tiff formata Keep layers

Save it to Assets folder

Open Unity

Page 26: Introduction to Unity

Petri Lankoski, [email protected]

Renderer & MaterialsAn object has renderer

Renderer draws the object to the screen Renderer has one or materials

Materials consists of Shader Resources that the shader needs for rendering

E.g., textures, colors, other assets

Multiple objects can share a material If the material is changed, the rendering of all

objects having that material is changed.

Page 27: Introduction to Unity

Petri Lankoski, [email protected]

Material

Shader

This part changes based on the selected shader

Preview

Page 28: Introduction to Unity

Petri Lankoski, [email protected]

Prefabs In Escape Package

Page 29: Introduction to Unity

Petri Lankoski, [email protected]

EnemyCollider• For

moving objects

Plays sounds

Enemy logic• Movement

speed• Damage

dealt• Sound files

Checkbox for Enabling/disablingscripts

Page 30: Introduction to Unity

Petri Lankoski, [email protected]

Colliders & Collision

STATIC

STATIC

STATIC

Page 31: Introduction to Unity

Petri Lankoski, [email protected]

Colliders & Collision

STATIC

STATIC

STATIC

Page 32: Introduction to Unity

Petri Lankoski, [email protected]

Enemy

Fine-tune how thisenemy perceives

Page 33: Introduction to Unity

Petri Lankoski, [email protected]

Enemy

Tag is used withwaypoints• Different tags

ensure that enemies keep their tracks

Page 34: Introduction to Unity

Petri Lankoski, [email protected]

Enemy Components / Billboard

Enemy consists of multiple billboards• Texture

animation• Textures• Animations

speed

Page 35: Introduction to Unity

Petri Lankoski, [email protected]

Enemy Components / Light

Page 36: Introduction to Unity

Petri Lankoski, [email protected]

Waypoints

This should match to Tag of an enemy• Default ok if

you do not have crossing tracks

Waypoint has a collider• Place it so that

an enemy can collide with it

Page 37: Introduction to Unity

Petri Lankoski, [email protected]

Door

Player reached the end if this is checked

These controls how completing the game is shown

Page 38: Introduction to Unity

Petri Lankoski, [email protected]

Door

The name of level where the door leads• If multiple

names are provided, one is selected randomly

Levels needs to be in Scenes in Build!

Page 39: Introduction to Unity

Petri Lankoski, [email protected]

Door with Lock

Page 40: Introduction to Unity

Petri Lankoski, [email protected]

Player Start Waypoint Player object only to the

first level

In levels 1- Place PlayerStart where

the player object begins

Page 41: Introduction to Unity

Petri Lankoski, [email protected]

Scenes (levels) Level 0

Splash screen Very minimal to

Levels 1+ Actual game levels

Page 42: Introduction to Unity

Petri Lankoski, [email protected]

Setting up Start ScreenFile -> New Scene

Download package: http://dl.dropbox.com/u/1380179/

escape_mainmenu.unitypackage

Assets -> Import Package -> Custom Package… Select escape_mainmenu.unitypackage

Add Player prefab to scene This is the only level where Player should be! You can add the Player for testing

Remove after level is ready

Page 43: Introduction to Unity

Petri Lankoski, [email protected]

Escape Splash Screen

Drag-and-drop

Draws the GUI

Page 44: Introduction to Unity

Petri Lankoski, [email protected]

Setting up Start Screen

Write the name of your first level

Page 45: Introduction to Unity

Petri Lankoski, [email protected]

GUI Skin

Changes how buttons and labels look like

Page 46: Introduction to Unity

Petri Lankoski, [email protected]

Start Screen

Page 47: Introduction to Unity

Build Game

Petri Lankoski, [email protected]

Select target and build

Select: • File -> Build Settings…

Alternatively:• File -> Build Settings…