Creating A Timed Run Challenge In Unity

Today I am making a challenge for my game, where the player must make it through 3 doors before time expires.

Today’s Objective: Create a player challenge where the player must run through 3 doors fast enough so that they don’t close prior to making it through.

The Code:

Programming this challenge is actually very easy, since once it starts, it only has to trigger animations at predefined intervals. First I create a TimedDoorRun class, and add variables for the door Animators and the trigger intervals:

And next are the methods for detecting activation collisions and starting the IEnumerator timed sequence:

The Scene:

The script goes on a parent object, above all the doors.

The collider on the same object is the activation trigger which starts the run. It is positioned at the start of the corridor. As for the timing intervals, they are of course determined through much trial and error.

The yellow box is a death zone which is enabled once the door closes, in case the player doesn’t make it, thus respawning them.

Optional: Add a warning message at the start:

I’ve decided to add a brief warning for the player to let them know what’s coming.

To do this, I need a few new variables, and a new method which will slot in between the existing 2 methods:



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.