2.5D Platform: Calling for an Elevator

Gabriel Perez
3 min readDec 25, 2021

I can now call for the elevator but it’s missing the elevator music :(

The idea is to have the player collect a number of coins to enable the ability to use the elevator panel and call the elevator by pressing the ‘E’ key.

I have an elevator game object all set up with an elevator panel. All I’ll need is two scripts. One for the Elevator, and the other for the Elevator Panel.

I created the scripts and attached them to their specified game object.

Elevator Panel Script

I want to detect for collision, and if it's the player, then I can press the ‘E’ key to call the elevator and turn on the light by changing the color of the material to a different color.

Elevator Script

When I press the ‘E’ key, I want to call the elevator so that it can go down from its current position to its target position. I used a bool for the Call Elevator function that will be called within in the Elevator Panel script. When I hit the ‘E’ key, the function will be called from there. I also want to take into account that there is a required number of coins I must collect for the elevator panel to work.

if (Input.GetKeyDown(KeyCode.E) && _canSwitch && player.GetCoins()               >= _requiredCoins)
{
_meshRend.material.color = _activeLight;
_elevator.CallElevator(true);
}

If the bool is true, then we are going down.

transform.position = Vector3.MoveTowards(transform.position, _target.position, _speed * Time.fixedDeltaTime);

If false, then we are going up.

transform.position = Vector3.MoveTowards(transform.position, _origin.position, _speed * Time.fixedDeltaTime);

I have two Transform positions that determine the points in space where I want the elevator to travel from A to B. And from B to A.

I also set the bool to false when the player exits the trigger.

private void OnTriggerExit(Collider other)
{
if (other.CompareTag(“Player”))
{
_canSwitch = false;
_elevator.CallElevator(false);
}
}

Conclusion

I now have a simple elevator that can be called to bring me up!

I want to mention that from now on, these dev logs will be more like personal entries where I write about areas I need help with. So it won’t be a complete guide, but more about thoughts that will help me remember. So I am sorry if a lot of it doesn't make any sense!

I also have my projects on GitHub.

You can access all of my scripts there!

Gabriel

--

--

Gabriel Perez

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