Using a Line Renderer to create a spinning laser trap
Interesting visual effects can be achieved through a scripted approach by creating Line Renderers. Unity Line Renderers can draw lines in the scene using assigned materials and their colors and Alpha Transparency. Lines can be drawn for many different reasons in games, such as to simulate laser beams, provide floating arrows to give the player hints on the direction to follow, and so on.
Figure 15.35: The rotating cube with the laser being emitted
In this recipe, we’ll create the effect of a rotating 3D Cube emitting a laser beam for a short distance. We’ll also learn how to create a scaled invisible cube in the same place as the laser, whose Box Collider can be used for collisions (as if they were with the laser).
Finally, in the There’s more... section, we’ll learn how to add these effects to the scene from the previous recipe to then create explosions when the player’s character...