Creating A Game Manager Class In Unity

Except perhaps, the tiniest of games, most games will need some sort of game manager to deal with data that affects the game in multiple places. Here, I will create one of my own.

Managers. They can do a lot.

Today’s Objective: Create a Game Manager to manage the game data and functions which are used by multiple parts of the game.

The Design:

Game Managers are commonly created using the Singleton design pattern, since there is usually only one of them, and it allows them to be accessed from almost anywhere. I’ll be using this pattern too.

In my case, the Game Manager class will manage the Pause/Restart/Quit gameplay functions, as well as an important game progression boolean.

The Code:

The general method (there are many variations) for creating a Singleton is like this:

A static CLASSNAME variable to hold the reference, and set the reference in Awake.

This class component will be placed on a GameObject in the game scene. Usually it’s own GameObject, probably called “Game Manager”.

To have it do what I need it for, I will need to add some more variables and methods:

This Manager’s methods can now be accessed and called from any class in the scene.

You may have noticed that the audio management section of this manager is actually done in another class, the AudioManager.

Unlike the GameManager, the AudioManager is not a Singleton. This was a choice I made because I wanted to access all other managers through the GameManager, like:

I felt that this was a nicer implementation. It can only be accessed through the GameManager (or GetComponent of course).

--

--

--

Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

A Framework for Overcoming Tough Bugs Without Pulling Your Hair Out

The Ongoing Cloud Transition

Data Capture Layer @ MakeMyTrip

test text for an analitytcs

title-pick

Development, Fast and Slow

Introducing Indeed — justLikeAPI’s newest platform!

Mapping sewer flow timing in ICM using SQL

How We Scheduled 20 Developer Interviews for Our Research in No-Time

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
Vincent Taylor

Vincent Taylor

Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.

More from Medium

Creating A Respawn/Checkpoint System In Unity

2D Mobile Game: Player Jump!

Working with Unity Ads

My journey becoming a Unity game developer: Variables-the building blocks of programming