Here you can see how to create a simple elevator using Unity 3d.
I wanted to create an elevator that connects 2 rooms on different floors of a building.
Here I used the default basic elements provided by Unity such as to create room and elevator I used cubes and the default third person character provided by Unity.
1>To create the building:-
- Create a simple building using cubes and cylinders as walls and floors(cubes) and pillars (cylinders).
- Use more than one cubes for the floors, the elevator is passing through. My middle second floor looks like -
- Now add all the floors and pillars in a new empty game object and name it as room. Add some light elements also to display light in the room. Here I have used a directional light and two point lights. Apply materials to the objects to look them like parts of room. For example, apply some tile textured material for the floors, some wallpaper textured materials to walls of the room etc.. I used textures those come with gimp, windows wallpapers and photoshop. I also used skyboxes here and a transparent material for my front wall. My room looks like-
- To get separate views of each floor I also added a camera at each floor that gives me the clear view of each floor. The following image shows the views of main camera(the full screen view ) and the cameras at floor 1 and floor 2.
2> To create the lift or elevator:-
- To create the walls of elevator use cubes. Also create buttons to open the elevator. I created two buttons on the pillar which is outside the elevator and one button on the pillar inside the elevator. For creating the buttons I used capsules and extended their collider element in Y axis. Again I used a transparent texture for the door of the elevator. I called the elevator "lift" and side walls of the elevator ,"liftwalls".Finally add a box collider to the elevator. My elevator looks like-
- I used Unity's default third person character so that I can check my lift (elevator) is actually working.
I created three C# MonoBehaviour scripts as follows:
- MainCamScript:- I am using this script to display the instructions about "how to control the character and how to use the elevator". I used simple OnGUI function to display the instructions.
- Lift:- This script is written for moving the elevator from one floor to another, and take whatever game object placed inside the elevator from one floor to another floor. When you place an object inside the elevator, make the object child of the elevator object otherwise the object will fall off the elevator as the elevator moves its position.
- LiftButton:- This Script is applied on the "Buttons" created to control the elevator. This script detects if the character is in front of the button and giving an input to open the elevator.
5> Animation:- For the lift door, I created a door open animation.
- You can get the source code of my project Here!