Mobile Game Progression

Creating an Elevator

While developing my mobile game, I decided to create one last stage for the game where the player gets on an elevator that strictly goes up. The player and elevator will be with with resistances from their enemies as they will be either bombarded with projectiles or enemies.

Creating the Elevator Object:

The way the elevator is going to work is very similar to how our enemies walk back and forth. We will need an elevator like platform sprite and also two empty game objects that will act as waypoints to create the path that the elevator is going to follow.

TLDR: you will need a platform sprite and also two waypoints which the elevator can create a pathway to follow.

I created an empty game object to house all of the platform sprites and another empty game object to house the elevator waypoints.

Finally to finish setting up the platform elevator, within the game object that houses the platform sprites, I added two box colliders, one that will be a trigger element while the other will physical.

TLDR: Create two box colliders, and make one collider as a trigger element. Then we are going to create a new C# script called Elevator and place that script within the same game object.

Scripting the Elevator:

Just like the enemy movement script we are going to need two transform variables called point A and point B. We will also need a speed variable to control how fast the elevator is going to move.

Next we will need a private vector 3 called current Target. This tell the elevator which waypoint they are currently on. We will also need to add an private bool called on Elevator which we will set to false by default. This is to control whatever script we need only when the bool is set to true.

In the start method we are going to set the current target to point A waypoint. That way whenever the scene is played the elevator will always be on the bottom.

Next we are going to create two On Trigger elements, one for Stay2D and another for Exit2D.

On the Stay2D we will need to check whenever the player has made contact with the trigger collider, and when the player does, we will set the bool “on Elevator” to be true. When that is true we will set the next target to point B waypoint.

On the Exit2D, we will basically set the bool “on Elevator” to be false. This script will stop the platform movement so the player has full control on when to move up.

Finally, to actually move the platform, within the Update method whenever the bool “on Elevator” is set to true, we will trigger an vector3 Move Towards function. Since the on Trigger Stay 2D method already preset the next target to be point B, the movement in the update script will be set to point B.

Finishing the Setup:

Back in Unity we are going to drag in the point A and point B waypoints into the script slot. Then we are going to drag the point B waypoint to the final location which will be on the top.

--

--

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
Simon Truong

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.