We will now write a simple script that is directly applicable in our example project and extend it afterwards to be more generic and reusable, using parameters.
Doors and elevators are typical interactive elements in buildings. Most buildings have no other moving parts. To rotate a door manually or to use scripting is not that different. However, there are a few tricks to get it correct. These are as follows:
Create a plane GameObject, positioned in the origin. Add a simple Cube, and name it
DoorLeaf
. Set its position to X=1
, Y=1.5
, Z=0
and scale to X=2
, Y=3
, Z=0.1
. This ensures that the lower side corner of the door leaf is sitting in the center or our scene.Load the local documentation from the menu by navigating to Help | Scripting Reference, which opens your default browser on the starting page of the locally installed Unity documentation, which is also accessible offline. On the first page there is a small menu to choose the language of all examples (JavaScript...