Tutorial Unity

Post on 18-Apr-2015

165 views 1 download

Transcript of Tutorial Unity

Tutorial Unity 3D

Reginaldo Costa

Afinal, o que é Unity3d?

E o que não é?

Versões gratuitas

x Versões pagas

Criando/abrindo

um projeto

O que incluir num

novo projeto?

Criando uma nova

cena

interface do UNITY

Importância de organizar o

projeto!

Formatos suportados

–3d max

–Blender

–FBX

–Imagens JPEG, GIF e PNG

–Arquivos do Photoshop

Geometria básica

Posicionando, rotacionando

e dimensionando

Importando objetos

3 formas de importação

– Import New Asset

–Arrastando do Explorer

–Colocando manualmente

Unity é semisciente!

Criando um terreno

Criando relevo

Câmera estática

Controlador de 1ª e 3ª pessoas

Corpos rígidos e gravidade

Exportando seu projeto

–Executável

–Web

Adicionando interação

Rotacionando

var speed = 20;

function Update () {

transform.Rotate(0, speed*Time.deltaTime, 0);

}

Rotacionando pelo nome

var speed = 20;

function Update () {

transform.Rotate(0, speed*Time.deltaTime, 0);

GameObject.Find('cubo2').transform.Rotate(0,

speed*Time.deltaTime, 0);

}

Rotação seguindo o mouse

var rotationSpeed = 10.0;

var lerpSpeed = 1.0;

private var speed = new Vector3();

private var avgSpeed = new Vector3();

static var dragging = false;

private var targetSpeedX = new Vector3();

function OnMouseDown(){

print('mouse donw');

dragging = true;

}

function Update () {

if (Input.GetMouseButton(0) /*&& dragging*/) {

speed = new Vector3(-Input.GetAxis ("Mouse X"), Input.GetAxis("Mouse Y"), 0);

avgSpeed = Vector3.Lerp(avgSpeed,speed,Time.deltaTime * 5);

} else {

if (dragging) {

speed = avgSpeed;

dragging = false;

}

var i = Time.deltaTime * lerpSpeed;

speed = Vector3.Lerp( speed,

Vector3.zero, i);

}

transform.Rotate( Camera.main.transform.up *

speed.x * rotationSpeed, Space.World );

transform.Rotate( Camera.main.transform.right *

speed.y * rotationSpeed, Space.World );

}

Verificando a ordem em que as cenas serão executadas

Criando um menu de cenas

function OnGUI () {

var posHorizontal = (Screen.width)/2;

var posVertical = 10;

if (GUI.Button( Rect(posHorizontal-

320,posVertical,150,40),"Cena 1")) {

Application.LoadLevel(1);

}

if (GUI.Button(Rect( posHorizontal-

160,posVertical,150,40),"Cena 2")) {

Application.LoadLevel(2);

}

if (GUI.Button(Rect(

posHorizontal,posVertical ,150,40),"Cena

3")) {

Application.LoadLevel(3);

}

if (GUI.Button(Rect( posHorizontal+170,

posVertical, 150,40),"Sair")) {

Application.Quit();

}

}

Criando uma tela de login

var campoNomeUsuario:String;

var campoSenha:String;

var texto:String = "";

function OnGUI() {

GUI.skin.button.hover.textColor = Color.cyan;

GUI.skin.button.active.textColor = Color.yellow;

GUI.skin.button.normal.textColor = Color.white;

var posHorizontal = (Screen.width) /2;

var posVertical = (Screen.height - 230) /2; GUI.Box(Rect(posHorizontal,posVertical,300,160),"VIRTUAL SUBSTATION - LOGIN");

GUI.Label( Rect (posHorizontal + 60,

posVertical +50, 80, 20), "Usuário:" );

GUI.Label( Rect (posHorizontal + 60,

posVertical +80, 80, 20), "Senha:" );

GUI.SetNextControlName("nomeUsuario");

campoNomeUsuario = GUI.TextField( Rect

(posHorizontal +140, posVertical +50, 110,

20), campoNomeUsuario );

GUI.SetNextControlName("senha");

campoSenha = GUI.PasswordField ( Rect

(posHorizontal +140, posVertical +80, 110,

20), campoSenha , "*"[0], 25);

if

(GUI.GetNameOfFocusedControl().Equals("")) {

GUI.FocusControl("nomeUsuario");

}

if( GUI.Button ( Rect (posHorizontal + 45,

posVertical +120, 100, 25),"Fazer Login" ) ){

if

((campoNomeUsuario.Equals('reginaldo')) &&

campoSenha.Equals('teste')) {

texto = 'Confere';

print('confere');

}

else{

texto = 'não confere';

print('não confere');

}

}

if( GUI.Button ( Rect

(posHorizontal + 155, posVertical

+120, 100, 25),"Sair" ) ){ //just a

button

Application.Quit();

}

if (!texto.Equals("")){

GUI.Label( Rect (posHorizontal +

60, posVertical +180, 80, 20),

texto);

}

}

Animação

Executando uma animação por script

var posHorizontal = (Screen.width - 50)/2;

function OnGUI () {

if(GUI.Button(Rect

(posHorizontal+60,Screen.height-60,50,50),"Play"))

{

GameObject.Find("Cube").animation.Play('animac

ao');

}

}

Onde conseguir mais?

• http://unity3d.qatohost.com/questions/index.html

• http://forum.unity3dbrasil.com/viewforum.php?f=3

• http://www.gamedev.com.br/forum/viewforum.php?f=60

Livros Unity 3D

Livros Unity 3D (2)