Menus Matter!
UI & Menus
The layer every real game needs: a title screen, settings with working volume and quality options that SAVE, a pause menu, smooth fades and juicy button feedback, wrapped around your RPG.
The layer every real game needs: a title screen, settings with working volume and quality options that SAVE, a pause menu, smooth fades and juicy button feedback, wrapped around your RPG.
Understand the Canvas system and build a resolution-proof layout.
Wire the menu buttons to real actions.
using UnityEngine;
using UnityEngine.SceneManagement;
public class MenuActions : MonoBehaviour
{
public void PlayGame() { SceneManager.LoadScene("Village"); }
public void QuitGame()
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
}
}
Add a working pause menu to the game scenes.
using UnityEngine;
public class PauseManager : MonoBehaviour
{
public GameObject pausePanel;
bool paused;
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
paused = !paused;
pausePanel.SetActive(paused);
Time.timeScale = paused ? 0f : 1f;
}
}
}
paused = ; pausePanel.SetActive(paused); Time.timeScale = paused ? : ;
Build a settings panel whose controls actually work.
using UnityEngine;
public class SettingsMenu : MonoBehaviour
{
public void SetVolume(float value)
{
AudioListener.volume = value;
}
public void SetQuality(int index)
{
QualitySettings.SetQualityLevel(index);
}
public void SetFullscreen(bool isOn)
{
Screen.fullScreen = isOn;
}
}
Persist every setting so it survives quitting the game.
public Slider volumeSlider;
void Start()
{
float vol = PlayerPrefs.GetFloat("volume", 1f);
AudioListener.volume = vol;
volumeSlider.value = vol; // sync the UI
}
public void SetVolume(float value)
{
AudioListener.volume = value;
PlayerPrefs.SetFloat("volume", value);
}
float vol = PlayerPrefs.("volume", );
volumeSlider. = vol;
Add fade-to-black transitions and complete the UI layer.
IEnumerator FadeAndLoad(string scene)
{
for (float a = 0; a < 1; a += Time.unscaledDeltaTime * 2f)
{
black.color = new Color(0, 0, 0, a);
yield return null;
}
SceneManager.LoadScene(scene);
for (float a = 1; a > 0; a -= Time.unscaledDeltaTime * 2f)
{
black.color = new Color(0, 0, 0, a);
yield return null;
}
}
Keep the Unity cheatsheet handy
MonoBehaviour, physics and UI in one place - use it beside this workshop.
Design your game UI icons!
Use Pixel Studio to create buttons, icons, and HUD elements - great pixel art assets for your Unity UI.
Vector2 movement = new Vector2(moveX, 0);void Update() {}float moveX = Input.GetAxis("Horizontal");rb.velocity = movement * speed;