2.5D Phase1 Framework: Moving Platforms

With having an elevator system going, I can reuse the logic for Moving Platforms!

2.5D Phase 1 Framework Challenge

As before, with my Elevator System challenge, I want the moving platform to move from point A to B non-stop.

I pretty much need the same logic behind the Elevator script. To keep it Modularized and not have duplicate code, I want to add an enum to state what kind of moving platform it is.

What I’ll Need?

In the elevator script, I want to add an enum to state what type of moving platform it is. I will use a switch statement to determine the type in Update.

Getting Started

I renamed the Elevator Script to “MovingPlatform.” I also added an enum above the class name.

public enum MovingPlatformType { None, Elevator, Platform }

I also want to serialize the field, initialize, and declare the enum in the MovingPlatform class so that I can have access to it in the inspector. It will allow me to select what type of platform it is.

[SerializeField] private MovingPlatformType _type;

For the switch statement, I added:

switch (_type)
{
case MovingPlatformType.Elevator:
if (transform.position == _pointA.position)
StartCoroutine(WaitBeforeSwitchingRoutine(true));
else if (transform.position == _pointB.position)
StartCoroutine(WaitBeforeSwitchingRoutine(false));
break;
case MovingPlatformType.Platform:
if (transform.position == _pointA.position)
_switch = true;
else if (transform.position == _pointB.position)
_switch = false;
break;
default:
print(“Please Select a type for the moving platform!”);
break;
}

If it’s an elevator, I want there to be a wait time before moving to the next point.

If it’s a regular moving platform, I want it to switch to the next point immediately.

And by default, I want Unity to send me a message via console that I forgot to select a type!

Now that I have modularized the script, I can set the type for the elevator prefab to type elevator and the moving platform prefab to type platform. And it’s working as intended!

Gabriel

--

--

--

Hello everyone, My name is Gabriel Perez, I am a Unity Developer and a creator who is always learning and experimenting.

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

Recommended from Medium

An Optimization Algorithm for Searching Most Relevant IDs

Text Extraction OCR Android App

bash, rename tip

AWS CodePipeline — Alexa Skill Deployment Pipeline

Four Easy Ways to Speed Up Your CI/CD Pipeline

ChainPad’s Airdrop Here!!!

The revolutionary cross-platform mobile development framework: is it Flutter 1.0?

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
Gabriel Perez

Gabriel Perez

Hello everyone, My name is Gabriel Perez, I am a Unity Developer and a creator who is always learning and experimenting.

More from Medium

Creating a triple shot for my Player

Working with Screen Space Reflections in Unity’s HDRP

Day 107: Ladder System Part 1

Sci-fi Lab — Collider