Using the UI tools

Revisado con versión: 4.6

-

Dificultad: Principiante

In this session we will use the UI Tools to make a simple example interface. Rather than simply discuss every component, we will see them in action. We expect to have ample time for Q&A both during and after the session. Tutor: Adam Buckner

Using the UI tools

Principiante User Interface (UI)

Download the Unity version 5x base project HERE.
Download the project images (including Character Icons and Demo UI Images) HERE.

PauseManager

Code snippet

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
#if UNITY_EDITOR
using UnityEditor;
#endif

public class PauseManager : MonoBehaviour {
    
    Canvas canvas;
    
    void Start()
    {
        canvas = GetComponent();
        canvas.enabled = false;
    }
    
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Pause();
        }
    }
    
    public void Pause()
    {
        canvas.enabled = !canvas.enabled;
        Time.timeScale = Time.timeScale == 0 ? 1 : 0;
    }
    
    public void Quit()
    {
        #if UNITY_EDITOR 
        EditorApplication.isPlaying = false;
        #else 
        Application.Quit();
        #endif
    }
}
#pragma strict
import UnityEngine.UI;

private var canvas : Canvas;

function Start()
{
    canvas = GetComponent.();
    canvas.enabled = false;
}

function Update()
{
    if (Input.GetKeyDown(KeyCode.Escape))
    {
        Pause();
    }
}

public function Pause()
{
    canvas.enabled = !canvas.enabled;
    Time.timeScale = Time.timeScale == 0 ? 1 : 0;
}

public function Quit()
{
    #if UNITY_EDITOR 
    EditorApplication.isPlaying = false;
    #else 
    Application.Quit();
    #endif
}

Tutoriales relacionados