2. 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)
3. 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
4. Unity 3D
• Setar BMAP para tamanho da tela:
• Classe Screen
• Screen.width / Screen.height
• Posição: Pivot = centro da imagem
function 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);
}
5. 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;
}
6. 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;
}
7. 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
8. Unity 3D
function 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;
}
9. Unity 3D
– Posição Z define ordem de renderização
–(qual mais a frente)
10. 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);
}
}