Laser Beam Controller
Draws a laser from an origin point to whatever it hits, and can carry an object along to the end of the beam. Pair it with a Laser Receiver Controller for laser puzzles.
Requires:
- Line Renderer (on any GameObject)
Line Renderer - Type: LineRenderer
- The Line Renderer that draws the beam. The script switches it to world space, so it can be on any GameObject.
Laser Origin - Type: Transform
- Where the beam starts. It fires along this Transform's forward (blue) axis.
Max Distance - Type: Float
- How far the beam reaches when it hits nothing.
- Default Value:
100.0
Layer Mask - Type: LayerMask
- The layers the beam stops at. If it's left at Nothing, the beam goes through everything (a warning is logged).
End Point Object - Type: GameObject
- Moved to the end of the beam every frame. Give it a collider on the Laser Receiver Controller's laser layer so receivers can detect the beam.
Hit Triggers - Type: Boolean
- Whether the beam stops at trigger colliders, such as a Laser Receiver's trigger. Leave it on when the End Point Object should land on a receiver.
- Default Value:
true
Usage Instructions:
- Add a Line Renderer with two positions, and this script.
- Assign the Line Renderer and Laser Origin, and set the Layer Mask.
- (Optional) Assign an End Point Object with a small collider on the laser layer (22 by default).