unity introduction for programmers

44
Unity3D Introduction Meeting GarageGeeks HQ 25 / 1 / 2012

Upload: noam-gat

Post on 18-Jul-2015

138 views

Category:

Engineering


21 download

TRANSCRIPT

Page 1: Unity introduction for programmers

Unity3D Introduction Meeting

GarageGeeks HQ

25 / 1 / 2012

Page 2: Unity introduction for programmers

Hi !

● I am Noam Gat● (Ex) Game Developer at Omek (with Unity)● Team member in Ogre3D graphics engine● GameIS Member (Join us!)

Page 3: Unity introduction for programmers

And you are...

● Mostly programmers● Little to no experience in game-dev

● Disagree? Raise your hand!

Page 4: Unity introduction for programmers

Lama Anglit?

כי זה יותר נוח!●, עדיף שיהיו מקושריםמושגים נלמד כמה ●

לסביבה שנעבוד בה. אני מפחד מעברית.●

Page 5: Unity introduction for programmers

Mission Statement

What are we NOT going to do ?

● Learn how to program / design games● Learn enough to develop a game on our own● Be 100% punctual and exact

Page 6: Unity introduction for programmers

Mission Statement

So what are we going to do ?

● Understand what a GAME ENGINE is● Get a broad sense of how to work with unity● Be able to work / talk with other UNITY devs

Page 7: Unity introduction for programmers

What is a game ?

Lets look at it from a

programmer's point of view...

Page 8: Unity introduction for programmers

What is a game ?

My “Hello world” program :● Has a start point and an end point

int main(){

print(“Hello world”);}

Often called a “procedural” program

Page 9: Unity introduction for programmers

What is a game ?

My “GUI / Forms / Widgets” program :● Doesn't have a known end point / time.

void OnButtonDown(){

MessageBox.Show(“Hello world”);}

Often called an “event based” program

Page 10: Unity introduction for programmers

What is a game ?

But why does “OnButtonDown” get called?

● Because the RUNTIME ENGINE invokes it.

We already don't control everything, but have

just enough power to do what we need.

Page 11: Unity introduction for programmers

What is an event ?

Depends on who you ask.

● GUI Apps? Mouse and keyboard movement

and presses, socket connections etc.● Games? Input, network, physics, and

(IMO the difference) - Time

Page 12: Unity introduction for programmers

What is a game ?

“A game is just an event-based application

in which things happen even if nobody does

anything”

Noam Gat, “Unity 3D Introduction Meeting”, 25.1.2012

Page 13: Unity introduction for programmers

What is a game engine?

A GAME ENGINE is an environment that

manages the different ENTITIES and

SUBSYSTEMS of a game and sends the

correct events to the code that the

developer writes.

Page 14: Unity introduction for programmers

What subsystems?

Central managers of different aspects● Scene graphs (Hierarchy)● Presentation (Graphics and Audio)● Input (On-site and remote)● Resources (Art and tech - Project)● Logic (Physics, AI, Behaviors)

Page 15: Unity introduction for programmers

Entities ?

● ENTITIES are a design pattern in which

systems are broken down into small

pieces that work together to create

complex behavior. In UNITY these are called

GAME OBJECTS.

Page 16: Unity introduction for programmers

Hello box

Page 17: Unity introduction for programmers

Hello box

What's in the box?● A TRANSFORM (position in the world)● A MESH (visual geometry)● A MATERIAL (rendering properties like color)● A COLLIDER (physics geometry)● A RIGID BODY (physical properties like mass)

Page 18: Unity introduction for programmers

Hello box

TRANSFORM

MESH

COLLIDER

MATERIAL

RIGID BODY

Do we always need everything?

Page 19: Unity introduction for programmers

Modularity

If we don't need physics, we can remove components.

Can we remove any more components?

Page 20: Unity introduction for programmers

Unity Editor

The INSPECTOR shows the components of an object

The SCENE view shows us the world as it is

The GAME view shows us the world from the camera

The HIERARCHY shows us the objects in the current scene

The PROJECT shows us all of the assets in the project

Page 21: Unity introduction for programmers

I want to code !

Coding in Unity is done via custom BEHAVIORS written

in the Mono (like .NET) environment.

Unity supports C# and variants of javascript, python.

We will use javascript / C# today.

Page 22: Unity introduction for programmers

I want to code

But first : How to navigate in the world in the editor.

MOVIE

Page 23: Unity introduction for programmers

Exercise #1 : Spinning Cube

1. Split into groups of 2 – 4 people

2. Create a new (empty) unity project

3. Create a scene and put a box in it, without physics

4. Create a javascript script in the project, and put the

following line in the Update function :

transform.RotateAroundLocal(Vector3.up, 1);

5. Attach the script to the cube in the scene

6. Press play and watch the magic happen!

Page 24: Unity introduction for programmers

Exercise #1 : Post Mortem

What happened?

1. The cube has a BEHAVIOR on it

2. UNITY calls its Update() function (why? docs)

3. The cube spins around a bit :

transform.RotateAroundLocal(Vector3.up, 1);

4. After spinning a bit for a lot of frames, it spins a lot

Page 25: Unity introduction for programmers

Exercise #1 : Post Mortem

Do we really know what is happening?

How fast is the cube spinning?

Page 26: Unity introduction for programmers

Exercise #2 : In Control

In the same group, modify the script so that

A: It contains a modifyable rotating speed, called

“turns per second”. Do this with this line :

public var turnsPerSecond = 1.0f;

B: The cube rotates along that speed. Hint :

Time.deltaTime, Mathf.PI

C: Try changing the parameter at

Runtime!

Page 27: Unity introduction for programmers

Exercise #2 : In Control

Solution :

transform.RotateAroundLocal(Vector3.up,

Time.deltaTime * turnsPerSecond * Mathf.PI * 2);

(Not important if you missed the 2)

Page 28: Unity introduction for programmers

Exercise #2 : In Control

We just learned how to configure our entities!

- It makes it easy to separate logic (code) from design

decisions (parameters for components).

- Even <Insert none-coder stereotype here> can

control the spinning cube!

Page 29: Unity introduction for programmers

Exercise #2.1 : In Control-er

Its not a game if we don't have any gameplay...

OMG LETS CONTROL THE SPINNING SPEED!!!

1. Declare two new parameters :

public var turnMoreKey = KeyCode.D;

public var turnLessKey = KeyCode.A;

2. Use Input.GetKey(...) to control the spinning speed.

Page 30: Unity introduction for programmers

Prefabs

After a few components your objects could get complicated.

You might want to classify a “cube with a transform spinner”

A “spinning cube”.

Page 31: Unity introduction for programmers

Exercise #2.2 : In Control-est

1. Create a prefab by dragging the cube to the project view.

2. Create one instance of the prefab for each team member

by dragging it to the scene.

Give each instance different control keys.

3. Battle it out for the spinningest cube!

Page 32: Unity introduction for programmers

Summary

Yadda yadda yadda.

I'll crowdsource this one.

Page 33: Unity introduction for programmers

Congratulations !

You now know Unity!

You can do anything you want with it!

Lets play spinning cube!

Page 34: Unity introduction for programmers

No, really.

You understand how different systems connect to each

other (we used the INPUT subsystem to control a

TRANSFORM COMPONENT of a specific

GAMEOBJECT)

Lets try to learn how to learn.

Page 35: Unity introduction for programmers

Exercise #3 : Gone Fishing

We want to know how each player is doing.

For each cube, display an on-screen string in the form of :

“Dudu's cube : Y rotation is 121.221 degrees”

How will we do this?

Help → Manual / Reference Manual / Scripting Reference

We are looking for a Graphical User Interface (GUI)

No cheating (Forums / internet) for this one please!

Page 36: Unity introduction for programmers

Hierarchies

Pretty good video here as well, I'll just play it

Page 37: Unity introduction for programmers

Exercise #4 : Tabletop

1. Create a simple scene of a table, a tray on the table

and some fruits on the tray.

2. Use parenting to create a correct hierarchy.

3. Place transform spinners on many elements in your

scene. Check that the scene makes sense when you

move them.

Page 38: Unity introduction for programmers

Summary

What have we learned?

● What should a GAME ENGINE give us● How does UNITY separate itself into different

SUBSYSTEMS and COMPONENTS● How can we extend UNITY and make our code run in it● How to answer our own questions about UNITY

Page 39: Unity introduction for programmers

Exercise #5 : Explore!

1. Open the “Angry Bots” sample project.

2. Spend about 5-10 minutes looking around, another

three minutes deciding on something to do in it,

then take 15-20 minutes to do it (if time permits).

3. GL HF!

Page 40: Unity introduction for programmers

What now ?

You don't know how to make games... YET

Page 41: Unity introduction for programmers

Be like the squirrel

You should (hopefully) be able to take a big problem

(“how to create a game?”) and rip it apart to smaller

questions and research into them on your own.

Page 42: Unity introduction for programmers

Give it a whirl

1. Global game jam

2. Advanced unity meetings

3. Facebook groups.

4. The only limit is yourself.

This weekend!

Israeli Unity3D developers UNITE!

Israeli Unity3d developers

Welcome to zombo.com

Page 43: Unity introduction for programmers

Questions?

Page 44: Unity introduction for programmers

Cheers!