Sequence Script Strategy in Unity

Interactive Ghost Train/Escape Room

I think of this sort of application as a fair ground Ghost Train. It takes you on a journey and while you can move around you’re mostly restricted to the narrative the game provides. I.e. with the exception of the final sequence the player only has limited movement, in this case they always remain seated. However, it is interactive, the player must complete a sequence of tasks similar in nature to an Escape Room. What does this mean for the design?

Developer vs. Designer

I’ve never liked this phrase, but it’s a convenient way of separating the problem. As with most front-end development the problem of integrating a graphical design with code is something that needs to be addressed. In this example I considered the ratio of effort to be much more Design than Coder. My rationale was this;

How to Implement a Ghost Train in Unity?

I’m not sure who suggested this (sorry I’ll quote you if I find out) but the use of the Cinemachine Dollycart and track is pretty much ideal for this sort of problem.

Dolly-cart Ghost Train
Timeline, ideal for fixed sequences

How to implement an Escape Room in Unity?

After reviewing the tasks I realized that this particular Escape Room mainly consisted of the following tasks;

  1. Play a voice over
  2. Flash and Enable a button
  3. Wait for the button to be pressed
  4. Play a dolly track
  5. Play a timeline
IF the player is in the MakeCoffee Scene 
AND the coffee machine button has not been pressed
THEN Flash and Enable the coffee machine button.

Sequence Steps

What I realized was that I could treat each tasks as a sequential step that has either completed or not. This means that if I can represent the tasks as a generic step then a designer could simply build any configuration of an Escape Room scene by drag and drop. Sounds good, fortunately it’s pretty easy to code too. Win-win.

Make Coffee in Unity

One of the Escape Room activities was to carry out the following;

  • Play a voice-over explaining that the player should make some coffee
  • Flash the light of the coffee machine button
  • Wait for the coffee button to be pressed
  • Create some coffee
  • Either wait for some coffee to be drunk or for a timeout
  • — end of scene —
Play a voice over
Example library of steps

The dumbest State Machine

A bit harsh sounding but it must be pretty close to the simplest state machine you can write;

Example sequence of items
How the scenes are just steps of a greater sequence

Easy testing

Since the app is now just distilled to a series of steps that wait to be completed this means that it makes testing really easy. With a quick Inspect Button Editor you can start any step, which also means you can start any sequence. Not only that but by exposing the ‘HasRun’ property of a step you turn certain steps off while testing…believe me if you’ve heard, “Why not make a cup of coffee” for the 400th time you’ll thank me ;)


This is really just another example of utilizing the way Unity can associate scripts with the scene hierarchy. It’s a powerful tool. It’s also example of tailoring your design to not only meet your in-game requirements (the voice over has to play) but with more non-live needs (make it easy for a non-dev to change).



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
Paul Marsh

Paul Marsh

Unity, VR, Enterprise and .Net Developer