unity3d tutorial

49
Unity3D Tutorial Unity3D Tutorial

Upload: kamaria-gyasi

Post on 03-Jan-2016

28 views

Category:

Documents


1 download

DESCRIPTION

Unity3D Tutorial. What is Unity. Free* multi platform (game) development tool Set up scenes visually Attach components to Gameobjects Logic in scripts (Mono-C# or Javascript) Integrated physics (PhysX), RakNet (networking), sound etc... Multi-platform, including web player - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Unity3D Tutorial

Unity3D TutorialUnity3D TutorialUnity3D TutorialUnity3D Tutorial

Page 2: Unity3D Tutorial

What is Unity

■ Free* multi platform (game) development tool Set up scenes visually Attach components to Gameobjects Logic in scripts (Mono-C# or Javascript) Integrated physics (PhysX), RakNet (networking), sound etc... Multi-platform, including web player

■ Unity 3D uses a left-handed coordinate system

Page 3: Unity3D Tutorial

What is Unity

■ 유니티의 역사 2005 년 6 월 , 덴마크의 무명 개발자 3 명이 모여 맥 전용

게임 엔진 공개 2005 년 11 월 , 윈도우 플랫폼 지원 2006 년 11 월 , 5 종류의 웹브라우저 지원 2008 년 Wii 와 아이폰 지원 2010 년 9 월 , 안드로이드 , Xbox 360, Playstation 3 지원 2012 년 2 월 , 플래시 지원 Unity 4.3 - 2D Game Development Walkthrough

Page 4: Unity3D Tutorial

Where to Get..

■ Tutorial http://unity3d.com/learn

■ Download http://unity3d.com/unity/download

Page 5: Unity3D Tutorial

Unity Interface

■ Learning the Interface The Main Editor Window is made up of several Tabbed

Windows, called Views• Project Browser , Hierarchy , Toolbar , Scene View • Game View , Inspector , Other Views

Page 6: Unity3D Tutorial

Unity Interface

■ Project Browser access and manage the assets that belong to your project

Page 7: Unity3D Tutorial

Unity Interface

■ Hierarchy contains every GameObject in the current Scene Parenting

• To make any GameObject the child of another, drag the desired child onto the desired parent in the Hierarchy.

A child will inherit the movement and rotation of its parent.

Two unparented objects One object parented to another

Page 8: Unity3D Tutorial

Unity Interface

■ Toolbar The Toolbar consists of five basic controls. Each relate to

different parts of the Editor.

Transform Tools : used with the Scene View Transform Gizmo Toggles : affect the Scene View display

Play/Pause/Step Buttons : used with the Game View

Layers Drop-down : controls which objects are displayed in Scene View

Layout Drop-down : controls arrangement of all Views

Page 9: Unity3D Tutorial

Unity Interface

■ Scene View use the Scene View to select and position environments, the player,

the camera, enemies, and all other GameObjects Scene View Navigation

• Move around on the X/Z plane : Use the arrow keys • Flythrough mode

Hold the right mouse button This turns your mouse and WASD keys (plus Q and E for up and

down) into quick first-person view navigation

• Orbit the camera around the current pivot point Hold Alt and left click-drag

• Drag the Scene View camera around Hold Alt and middle click-drag

• Zoom the Scene View Hold Alt and right click-drag

Page 10: Unity3D Tutorial

Unity Interface

■ Scene View Scene Gizmo

• displays the Scene Camera's current orientation• allows you to quickly modify the viewing angle• Each of the coloured "arms" of the gizmo represents a

geometric axis• Click on the text underneath the gizmo to switch between

the normal perspective view and an isometric view

Page 11: Unity3D Tutorial

Unity Interface

■ Scene View Positioning GameObjects

• Focusing Select any GameObject and press the F key

• Translate, Rotate, and Scale use the Transform Tools in the Toolbar to Translate, Rotate,

and Scale individual GameObjects

Page 12: Unity3D Tutorial

Unity Interface

■ Game View Representative of your final, published game Play Mode

• Use the buttons in the Toolbar to control the Editor Play Mode and see how your published game will play

Game View Control Bar

Page 13: Unity3D Tutorial

Unity Interface

■ Inspector displays detailed information about your

currently selected GameObject, including all attached Components and their properties

Modeling Texture Sound

Page 14: Unity3D Tutorial

Unity Interface

■ Other Views The Console shows logs of messages, warnings, and errors. The Animation View can be used to animate objects in the

scene. The Profiler can be used to investigate and find the

performance bottle-necks in your game. The Asset Server View can be used to manage version

control of the project using Unity's Asset Server. The Lightmapping View can be used to manage lightmaps

using Unity's built-in lightmapping. The Occlusion Culling View can be used to manage

Occlusion Culling for improved performance.

Page 15: Unity3D Tutorial

Customizing Your Workspace

■ Customizing Your Workspace customize your Layout of Views by click-dragging the Tab of

any View to one of several locations

Page 16: Unity3D Tutorial

Unity Project

■ 프로젝트 구조 Scene 과 Asset 으로 구분

Page 17: Unity3D Tutorial

Unity Project

■ Scene 게임제작을 위해 제공하는 하나의 가상 3 차원 공간 게임 ( 프로젝트 ) 은 여러 개의 Scene 으로 구성

Page 18: Unity3D Tutorial

Unity Project

■ Asset : Scene 을 구성하기 위해 공용으로 사용되는 물질적인 자원

Page 19: Unity3D Tutorial

Unity Package

■ Unity Asset 원본 파일이외에도 인스펙터 뷰를 통해 추가적으로 설정되는

부가정보가 합쳐져서 최종적으로 사용가능 유니티로 생성된 패키지 : .unitypackage Package Load

• Assets Import Package Custom Package

디렉토리의 전체 경로에 한글이 들어가면 제대로 동작하지 않음

Page 20: Unity3D Tutorial

Unity Package

■ Unity Basic Package

Page 21: Unity3D Tutorial

Prefabs

■ Prefabs a type of asset : a reusable GameObject stored in Project View Prefabs 으로 만들어진 Game Object 는 Prefab 설정을

변경하면 만들어진 Game Object 의 설정도 동일하게 변경됨

Page 22: Unity3D Tutorial

Prefabs

Creating Prefabs

1. Choose Assets->Create->Prefab from the menu bar and name your new Prefab.

2. In Hierarchy View, select the GameObject you wish to make into a Prefab.

3. Drag & drop the GameObject from the Hierarchy onto the new Prefab in Project View.

• The GameObject's name will turn blue to show that it is a Prefab.

Page 23: Unity3D Tutorial

Your First Game

■ Project: Roll-a-Ball Create a simple rolling ball game that teaches you many of

the principles of working with Game Objects, Components, Prefabs, Physics and Scripting

Page 25: Unity3D Tutorial

Setting up the game

■ Setting up the game File Menu New Project “Roll-a-ball” Save Scene (Ctrl + S)

• Create New Folder “_Scene”• Save as “MiniGame.unity”

Create Game Object “Plane”• Using Menu

GameObject Create Other Plane

• Using Hierarchy Window Create Tab Plane

• Rename “Ground”• Select Gear Menu in Inspector View Reset• Focusing : Select Game Object “Ground”

Edit Frame Seleceted || F Key

Scale X 2, Y 1, Z 2

Page 26: Unity3D Tutorial

Setting up the game

■ Setting up the game Create Game Object “Sphere”

• GameObject in Main Menu Create Other Sphere• Rename “Player” & Reset• Select Gear Menu in Inspector View Reset• Focusing Game Object “Player” (F Key)• Change Position Y 0.5

Scene View Game View

Page 27: Unity3D Tutorial

Setting up the game

Add Directional Light• Create Tab in Hierarchy View Directional Light

Rename “Main Light” & Reset Change Transform in Inspector View

− Rotation X 30, Y 60 Shadow Type : Soft Shadow Resolution: Very High Resolution

• Duplicate “Main Light” Rename “Fill Light” & Reset Change Transform in Inspector View

− Rotation X -30, Y -60 Change Color & Intensity 0.1 Turn off Shadow

Page 28: Unity3D Tutorial

Setting up the game

■ Organizing Hierarchy Create Empty Game Object Create Empty Rename “Lighting” & Reset to The Origin Drag “Main Light” & “Fill Light” into “Lighting” Change Y Position 100

Page 29: Unity3D Tutorial

Moving the player

■ Moving the player Moving the player object using player input and physics forces. Select “Player” & Add Component “Physics”

1. Using Main Menu: Component Physics Rigidbody

2. Using Inspector : Press Button “Add Component” Making Scripts

• Create New Folder in Project View

• Rename “Scripts”

• Create C# Scripts1. Assets Create C# Scripts (Main Menu)

2. Create C# Scripts in Project View

3. Select Player Add Component New Scripts Rename “PlayerController”

Page 30: Unity3D Tutorial

Moving the player

Open MonoDevelop• Select “PlayerController” & Press Open Button in Inspector• Written below code & Build

Page 31: Unity3D Tutorial

Moving the player

■ Update() Called Every Frame Used for regular updates such as

• Moving Non-Physics objects, Simple Timers, Receiving Input Update interval time vary ( 호출될 때 마다 인터벌시간이 다름 )

■ FixedUpdate() Called Every Physics Step Fixed Update interval are consistent ( 인터벌시간 항상 일정 ) Used for regular updates such as

• Adjusting Physics (Rigidbody) objects

■ LateUpdate Called once per frame, after Update() has finished Used for a following camera ( 모든 Update 함수가 호출된 후 호출 )

Page 32: Unity3D Tutorial

Moving the player

Open MonoDevelop• Using Help (Ctrl + ' )

Page 33: Unity3D Tutorial

Moving the player

Return to Unity Editor• Input Manager

EditProject SettingsInput menu

• Play (Ctrl + P) Use keyboard w, s ,a , d

• Change Script Code & Playusing UnityEngine;

using System.Collections;

public class PlayerController : MonoBehaviour {

public float speed;

void FixedUpdate() {

float moveHorizontal = Input.GetAxis("Horizontal");

float moveVertical = Input.GetAxis("Vertical");

Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

rigidbody.AddForce(movement*speed*Time.deltaTime);

}

}

deltaTime : The time in seconds it took to complete the last frame

Page 34: Unity3D Tutorial

Moving the camera

■ Moving the camera Select “Main Camera” & Change Transform

• Position Y10, Rotation X 45 Make “Main Camera” as Child of Player

• Move & Rotate “Player”• But, Play Game No Good

Camera follow the ball with rotation

• Detach “Main Camera”

Page 35: Unity3D Tutorial

Moving the camera

Create New script “CameraController”• Add Component to “Main Camera”• Open MonDevelop & Edit “CameraController”• Assign “Player”

Play The Game• Camera follow the ball without rotation

using UnityEngine;

using System.Collections;

public class CameraController : MonoBehaviour {

public GameObject Player;

private Vector3 offset;

// Use this for initialization

void Start () {

offset = transform.position;

}

void LateUpdate () {

transform.position = Player.transform.position + offset;

}

}

Page 36: Unity3D Tutorial

Creating pick-up objects

■ Creating pick-up objects Setting up the play area and creating pick-up objects. Making Walls

• Create Empty “Walls” & Reset Transform• Create New Cube “West Wall”

Move “West Wall” into “Walls” Change Scale: X0.5, Y2, Z20.5, Translate: X-10

• Duplicate “West Wall” “East Wall” Change Translate: X10

• Duplicate “West Wall” “North Wall” Scale: X20.5, Y2, Z0.5, Translate: Z10

• Duplicate “North Wall” “South Wall” Translate: Z-10

Page 37: Unity3D Tutorial

Creating pick-up objects

Create Pickups• Create New Cube “PickUp” & Reset• Select “Player” & Deselect checkbox• Select “PickUp”

Change Transform− Position: Y0.5, Rotation: X,Y, Z45, Scale: X,Y,Z0.5

• Rotating “PickUp” Create New Script “Rotator” Open MonDevelop & Edit “Rotator”

Play The Game : Rotating Cube

using UnityEngine;

using System.Collections;

public class Rotator : MonoBehaviour {

void Update () {

transform.Rotate(new Vector3(15, 30, 45)*Time.deltaTime);

}

}

Page 38: Unity3D Tutorial

Creating pick-up objects

Making Prefabs Asset• Create Folder “Prefabs” in Project View

Drag “Pickup” object into “Prefabs” folder

• Create Empty “PickUps” & Reset Drag “Pickup” object into “PickUps” Select Y Axis in Gizmo Change Local Global mode

• Duplicate “PickUp” (Ctrl + D) Creating 12 Pickups

Page 39: Unity3D Tutorial

Collecting Pick-Up Object

■ Collecting Pick-Up Object discussing physics, collisions and triggers. Collider( 충돌자 ) : 충돌시 오브젝트의 경계를 설정하는

콤포넌트• Select “Player” & select checkbox• Check Sphere Collider• Open MonDevelop & Edit “PlayerController”

void OnTriggerEnter(Collider other) {

if(other.gameObject.tag == "PickUp") {

other.gameObject.SetActive(false);

}

}

Page 40: Unity3D Tutorial

Collecting Pick-Up Object

■ There are 3 types of colliders in Unity3D: Static colliders

• Used for collisions for anything that never moves in your level (level floors, walls, obstacles, etc)

• these should only contain a collider without a rigidbody. Dynamic colliders

• Used for collision detection for dynamic objects (enemies, bullets, boulders, etc)

• the setup is pretty straightforward, a rigidbody is attached to a collider

Kinematic colliders• Used for collisions for anything that moves using code and not

physics (moving platforms, elevators, etc) • these must have a rigidbody marked as kinematic with a

collider.

Page 41: Unity3D Tutorial

Collecting Pick-Up Object

Add Tag • Add Tag “PickUp” Using Tag Manager • Select Prefabs “PickUp”

Assign Tag “PickUp” Select checkbox “Is Trigger” in Box Collider

• Play It !!! : Collecting Box

Page 42: Unity3D Tutorial

Collecting Pick-Up Object

One Small Mistake• Static colliders by changing the Transform position since this

will impact heavily on the performance of the physics engine Dynamic Collider : Add rigidbody into “PickUp” Prefabs

• Triggers do not collide “Ground”

• Simple Solution : Uncheck “Use Gravity”• Better Solution: Kinematic colliders

Check “Use Gravity” & “Is Kinematic”

Page 43: Unity3D Tutorial

Displaying text

■ Displaying text Counting, displaying text and ending the game. Create Object

• Create Empty “Display Text” & Reset• Create GUI Text “Count Text”

Making Child: Drag into “Display Text” Change Transform : X0, Y1 Change GUIText : Pixel Offset X10, Y-10

Page 44: Unity3D Tutorial

Displaying text

Select “PlayerController” : Open MonDevelop & Edit Select “Player” & Assign “Count Text”

Play It

public class PlayerController : MonoBehaviour {

public float speed;

public GUIText countText;

private int count;

void Start() {

count=0;

SetCountText ();

}

void FixedUpdate() { ….. 중략 }

void OnTriggerEnter(Collider other) {

if(other.gameObject.tag == "PickUp") {

other.gameObject.SetActive(false);

count = count + 1;

SetCountText ();

}

}

void SetCountText() {

countText.text = "Count: " + count.ToString();

}

}

Page 45: Unity3D Tutorial

Displaying text

Create GUI Text “Win Text”• Making Child: Drag into “Display Text”• Change Transform : X0.5, Y0.75• Change GUIText

Anchor middle center Alignment center

• Select “PlayerController” Open MonDevelop & Edit

• Select “Player” Assign “Win Text”

Play It

public class PlayerController : MonoBehaviour {

public float speed;

public GUIText countText;

private int count;

public GUIText winText;

void Start() {

count=0;

SetCountText ();

winText.text="";

}

…. 중략

void SetCountText() {

countText.text = "Count: " + count.ToString();

if(count==12) winText.text ="YOU WIN!";

}

}

Page 46: Unity3D Tutorial

Publishing the game

■ Publishing the game Publishing the game to a web player Save Scene File Build Setting

• Select Platform “Web Player”• Drag & Drop “MiniGame.unity”• Build

Create Folder “Builds” Save as “Roll-a-Ball_v01”

Page 47: Unity3D Tutorial

Publishing the game

■ Web Play Copy ““Roll-a-Ball_v01” Folder to Web Server Failed to download data file ??

• adding the custom file required to define own MIME Types• put a custom web.config in the same folder of the

"*.unity3d" files Play!!

<configuration>

<system.webServer>

<staticContent>

<mimeMap fileExtension=".unity3d" mimeType="TYPE/SUBTYPE" />

</staticContent>

</system.webServer>

</configuration>

web.config

Page 48: Unity3D Tutorial

Publishing the game

Page 49: Unity3D Tutorial

Reference

■ Reference Project: Roll-a-Ball Unity3D Tutorial Walkerboy studio Tutorial List Unity Korea http://www.unitylearning.co.kr/main/main.asp