Published in

Nerd For Tech

# Calling the elevator

Now that we have the prerequisites out of the way, let’s get the elevator moving! If you’ve followed along with the moving platform scripts, this is going to be really familiar!

Let’s prepare our elevator by duplicating it, moving it down to where it should go and we’ll call it PointB, duplicate it again and call it PointA.

Since we only want the transform information, select both points and delete everything except the transform. Again I’m using the remove component option in the pulldown. Sorry for the cutoff window.

Next to keep things organized, create an empty called Elevator Holder and place the Elevator and Points in it.

And we’re ready to get things moving! Create a new script called Elevator and drag it into the Elevator object (Not the Elevator Holder).

Let’s create holders for PointA and PointB

Might as well throw a speed variable in as well. Now let’s drag the points into their proper slots.

We’ll want to know whether or not the elevator is going down so it’ll be a good idea to create a boolean for that.

Before we start writing any logic, let’s create a FixedUpdate that actually brings our elevator down to pointB. We’ll use the same method we learned in the moving platforms tutorial.

Let’s run the game:

Ok! Now we’re going places! Now we only want the elevator to move when we call it, our boolean _goingDown is already false, so let’s wrap it with that.

so now we need to create a connection to the elevator panel, we’ll create a method called ‘CallElevator’ where we’ll set _goingDown to true when it’s called.

Now let’s call it from our ElevatorPanel script!

Since we’re looking for a component outside of our script, it’s generally a good idea to null-check so if it isn’t found, it will notify us and we can do some debugging.

Ok, enough coding, let’s run this thing!

Awesome! We now have an elevator at our beck and call! But coming down is only half the battle, tomorrow we’ll complete the logic for it to go back up as well as fix anything that may come up.

--

--

--

## More from Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

## Esteban Ibarra

cartoonist, game artist, and wanabe gamedev.