Hello,
First of all, here is a video for reference throughout the post. And here is my code.
In my project, I currently have a laser set up using LineRenderer. The laser will go on indefinitely. When a player or object collides with the laser, the laser stops at that collision point and has that spark effect turn on (as seen in the video).
On the opposite side of where the laser starts is a receiver point with a red indicator. I’m trying to make it so when the laser touches the white cube below the red indicator, the indicator will change to a green indicator. And of course, when the laser is not touching it, it changes to a red indicator.
I have the code, but the cube can’t detect when the laser is colliding with it. The laser stops when it collides with the cube, but the cube can’t detect the laser is touching it and thus won’t change the indicator.
I thought about adding a collision to the laser, but 1. there isn’t any collision for line renderers, and 2. I still want to be able to allow the player/a cube to interrupt the laser.
So, I’m stuck on what to do next.
Any help is appreciated. Thanks 
You definitely want to be using raycasts for this.
void Update()
{
// Bit shift the index of the layer (8) to get a bit mask
int layerMask = 1 << 8;
// This would cast rays only against colliders in layer 8.
// But instead we want to collide against everything except layer 8. The ~ operator does this, it inverts a bitmask.
layerMask = ~layerMask;
RaycastHit hit;
// Does the ray intersect any objects excluding the player layer
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, layerMask))
{
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
Debug.Log("Did Hit");
}
else
{
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 1000, Color.white);
Debug.Log("Did not Hit");
}
}
Specially the part the says hit.distance is important for you as that will stop your laser on the interuptor and return a collision detection with which you can do as you please.
Without knowing exactly how you’re shooting your laser I cant tell for sure, but it should be very similar to how you shoot your line renderer.
Instead of referencing a method in a seperate script, I introduced both red and green indicator gameobjects to the Laser script, so if the laser touches the end white block, it disables the red indicator and enables the green indicator. And if the laser isn’t touching it, then the green indicator gets disabled and the red one is enabled.
using UnityEngine;
using System.Collections;
public class Laser : MonoBehaviour {
public GameObject sparks;
public GameObject redIndicator;
public GameObject greenIndicator;
private LineRenderer lr;
// Use this for initialization
void Start () {
lr = GetComponent<LineRenderer>();
}
// Update is called once per frame
void Update () {
lr.SetPosition(0, transform.position);
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.forward, out hit))
{
if (hit.collider)
{
lr.SetPosition(1, hit.point);
sparks.SetActive(true);
sparks.transform.position = hit.point;
greenIndicator.SetActive(false);
redIndicator.SetActive(true);
if (hit.collider.tag == "LaserEnd")
{
lr.SetPosition(1, hit.point);
sparks.SetActive(false);
redIndicator.SetActive(false);
greenIndicator.SetActive(true);
}
}
}
else
{
lr.SetPosition(1, transform.forward * 5000);
sparks.SetActive(false);
greenIndicator.SetActive(false);
redIndicator.SetActive(true);
}
}
}
Thanks for your help 