Game Design Pattern: Command Pt.2- Game Dev Series 137

Objective: playing stored contents/command by using CommandManager.

In this tutorial, we will continue to create a manager class that would play all command we created in order, and also can rewind or clear it.

CommandManager

To make it easier to call, the CommandManager must be a singleton. Then create a list variable to it to store the executed command.

Inside this manager, we would need some methods to do the following functions:

  • Adding command into list
  • Playing all command from list
  • Playing all command in rewind from list
  • Setting all color into white when finished changing
  • Reset the list

Adding command into list

In this method, we would pass in the current executed command when clicking on cube, and store it into list.
By doing this, we can use List.Add(object).

Then we need to call this method in PlayerInput after execute the command.

Playing & reverse all command

The Playing is quite simple. We need to make it replay all result of command in list, what’s more, we will need it to play one per second. The best way to present this is creating a coroutine.

For the rewind playing, we can use the reverse function of LINQ to do this part. Before we using LINQ, you will need to add a namespace of System.Linq to this script.
Then we create another coroutine to reverse playing the list.

Done and reset

All you need to set cubes to white, is calling every cubes by tag, then set their color to white in foreach loop.

The last one: reset.
Just Clear out the whole list and that is all you need.

Assign to buttons and test

Now we just need to create an empty object to contain this manager class in game scene, and assign these methods to all buttons.

And we can test the result of using Command Design Pattern.

--

--

--

A passionate gamer whose goal is to work in video game development.

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

Recommended from Medium

Monthly Summary: April 2020

Setting up a validator for E-Money [emoney-3]

How to make an NFT Minting button on a website with no-code

Memory Unit Conversions with Python and SQL

E = mc squared on a chalkboard.

Disbursement Summary TDP 10.20.210

How to build an in-car voice assistant with Dasha AI

Google SpreadSheet into a REST API

Terra Delegation Program 2022 Round 1: Applications

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
S.J. Jason Liu

S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.

More from Medium

Adding the speed boost powerup

Day 105: Working with Animation Events in Unity

Unity : AI && NavMesh [FSM : (Finite State Machine with Enum)]

A Brief Introduction to Cinemachine and Timeline in Unity