Aula menus

10

Click here to load reader

description

Aula de criação de menus para unity 3D

Transcript of Aula menus

Page 1: Aula menus

Projeto de jogos RAD:GUI Texture e Menus

Augusto Bülow

Page 2: Aula menus

Unity 3D• GUITexture: imagens 2D renderizadas

diretamente na tela• HUD: elementos de interface e display• Imagens: load, logos, cut-scenes, etc.• Botões / menus (2D)

Page 3: Aula menus

Unity 3D• GUITexture:

• Importar imagem 2D (BMAP)• Criar GUITexture

• Propriedades básicas• posicionamento / escala• cor (adicional / tint)• PixelInSet (retangulo)

• Posicao e tamanho em pixels• Bordas: protege bordas de escala

Page 4: Aula menus

Unity 3D• Setar BMAP para tamanho da tela:• Classe Screen

• Screen.width / Screen.height• Posição: Pivot = centro da imagemfunction Start () {

var size_x = Screen.width;

var size_y = Screen.height;

var pos_x = -size_x /2;

var pos_y = -size_y /2;

guiTexture.pixelInset = Rect (pos_x, pos_y, size_x, size_y);

}

Page 5: Aula menus

Unity 3D• Criar efeito Tint / transparência no BMAP

• Componente de Cor (0..1) • color.a = alpha / transparência

var cor = 0.0;

function Update () {

if (cor < 0.5) { cor += 0.1 * Time.deltaTime; }

guiTexture.color.r = cor;

guiTexture.color.g = cor;

guiTexture.color.b = cor;

}

Page 6: Aula menus

Unity 3D• Criar movimento nos bmaps

• pelo retângulo ( guiTexture.pixelInset )• pelo transform.position

...

if (cor < 0.5) {

transform.position.y += 0.1 * Time.deltaTime;

}

Page 7: Aula menus

Unity 3D• Utilizando BMAPS como botões• Eventos do mouse (Functions / Messages)

• OnMouseDown

• OnMouseOver

• OnMouseExit

• OnMouseExit

• Criar / Inserir script com código especifico para as chamadas

Page 8: Aula menus

Unity 3Dfunction OnMouseDown () {

Application.LoadLevel (1);

}

function OnMouseOver () {

guiTexture.color.r = 1;

guiTexture.color.g = 0.1;

guiTexture.color.b = 0.1;

}

function OnMouseExit () {

guiTexture.color.r = 0.5;

guiTexture.color.g = 0.5;

guiTexture.color.b = 0.5;

}

Page 9: Aula menus

Unity 3D– Posição Z define ordem de renderização

–(qual mais a frente)

Page 10: Aula menus

Unity 3D– Usar mesmo script para componentes do menu– Checar nome / definir ação

function OnMouseDown () {

if (gameObject.name == "botao1") {

Application.LoadLevel (1);

}if (gameObject.name == "botao2") {

Application.LoadLevel (2);}

}