TrafficLights into your
Environment follow steps below.
Environment you are creating there will most likely be many
TrafficLights that should look and work the same way.
To simplify the process of creating an environment it is advised to create one
TrafficLight of each type with this tutorial and then save them as prefabs that you will be able to reuse.
1. Add TrafficLight Object
Map object in the Hierarchy view add a new Child Object and name it appropriately.
2. Add a Mesh Filter and select meshes
Click on the
Mesh filterand select it by clicking on it.
TrafficLightspecify the mesh you want to use.
3.Add a Mesh Renderer and specify materials
The same way as above search for
Mesh Rendererand select it.
Now you need to specify individual component materials.
For example in the
Traffic.Lights.001mesh there are four sub-meshes that need their individual materials.
To specify a material click on the selection button on
Materialselement and search for the material you want to use and select it.
Repeat this process until you specify all materials. When you add one material more than there are sub-meshes you will see this warning. Then just remove the last material and the
Different material for every bulb is necessary for the color changing behavior that we expect from traffic lights. Even though in most cases you will use the same material for every
Bulb, having them as different elements is necessary. Please only use models of
TrafficLightsthat have different
Materials Elementsfor every
When specifying materials remember the order in which they are used in the mesh. Especially remember what
Materials Elementsare associated with every
TrafficLight. This information will be needed later.
In the case of
Traffic.Lights.001the bulb materials are ordered starting from the left side with index 1 and increasing to the right.
4. Add a Mesh Collider
The same way as above search for
Mesh Collider and select it.
Collider may not seem useful, as the
TrafficLight in many cases will be out of reach of vehicles.
It is however used for LiDAR simulation, so it is advised to always add colliders to Objects that should be detected by LiDARs.
5. Position TrafficLight in the Environment
Finally after configuring all visual aspects of the
TrafficLight you can position it in the environment.
Do this by dragging a
TrafficLight with a square representing a plane or with an arrow representing one axis.
6. Add TrafficLight Script
Traffic Light Script will enable you to control how the
TrafficLight lights up and create sequences.
Add Component, search for the
Traffic Lightscript and select it.
You should see the
Bulb Emission configalready configured. These are the colors that will be used to light up the Bulbs in
TrafficLight. You may adjust them to suit your needs.
You will have to specify
Bulb material config, in which you should add elements with fields:
Bulb Type- One of the predefined Bulb types that describes the Bulb (its color and pattern).
Material Index- Index of the material that you want to be associated with the Bulb Type. This is where you need to use the knowledge from earlier where we said you have to remember what Materials Element corresponds to which bulb sub-mesh.
Bulb configuration example
Here we specify an element Type as
RED_BULBand associate it with Material that has an index 3. This will result in associating the right most bulb with the name
RED_BULB. This information will be of use to us when specifying
Once you have added
TrafficLights to your
Environment, you can start configuring
RandomTraffic which will add moving vehicles to it! Details here.