UI Manager

One UI Manager to Rule them All

In this article we will create one UI Manager to use for both our win and lose cutscene menu’s.

Create Files

Create Empty Game Object > Rename to UI Manager

Create New C# Script > Name to UIManager

Attach C# Script to UI Manager Game Object with drag and drop

UI Manager Script

Again we will create a singleton from our UI Manager. We added a restart scene function and a quit application function.

using UnityEngine;
using UnityEngine.SceneManagement;

public class UIManager : MonoBehaviour
{
private static UIManager _instance;
public static UIManager Instance
{
get
{
if (_instance == null)
{
Debug.LogError("UI Manager is null");
}
return _instance;
}
}

private void Awake()
{
_instance = this;
}

public void RestartScene()
{ SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}

public void QuitApllication()
{
Application.Quit();
}

Link Script to Buttons

Select the Button in the Hierarchy > Inspector > Button (Script) > OnClick() > +
Drag in > UI Manager (Game Object) >No Function (dropdown) > UI Manager > Select Function you want to use (ex. RestartScene)

UIManager.RestartScene()

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tristan Engel

Tristan Engel

18 Followers

Aspiring developer that’s self-learning Unity & C# to transition to a career with Unity. I got a passion for creating interactive experiences.