Line Renderer flickering when updated in runtime

Check this 1 to see the issue in action. the code:

using UnityEngine;
[RequireComponent(typeof(LineRenderer))]
public class MirrorReflect : MonoBehaviour
{
	//the attached line renderer
	private LineRenderer lineRenderer;

	//the number of reflections
	public int nReflections = 2;
	//max length
	public float maxLength = 100f;

	//private int pointCount;
	void Awake()
	{
		//get the attached LineRenderer component  
		lineRenderer = GetComponent<LineRenderer>();
	}
	void Update()
	{
		//clamp the number of reflections between 1 and int capacity  
		nReflections = Mathf.Clamp(nReflections, 1, nReflections);

		Ray2D ray = new Ray2D(transform.position, transform.right);

		//start with just the origin
		lineRenderer.positionCount = 1;
		lineRenderer.SetPosition(0, transform.position);
		float remainingLength = maxLength;
		//bounce up to n times
		for (int i = 0; i < nReflections; i++)
		{
			RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, remainingLength);
			// ray cast
			if (hit.collider != null)
			{
				//we hit, update line renderer
				lineRenderer.positionCount += 1;
				lineRenderer.SetPosition(lineRenderer.positionCount - 1, hit.point);
				// update remaining length and set up ray for next loop
				remainingLength -= Vector3.Distance(ray.origin, hit.point);
				ray = new Ray2D(hit.point, Vector3.Reflect(ray.direction, hit.normal));
				// break loop if we don't hit a Mirror
				if (hit.collider.tag != "Mirror")
					break;
			}
			else
			{
				// We didn't hit anything, draw line to end of ramainingLength
				lineRenderer.positionCount += 1;
				lineRenderer.SetPosition(lineRenderer.positionCount - 1, ray.origin + ray.direction * remainingLength);
				break;
			}
		}
	}
}

Help?

Oh man! tell me you found an answer @Spacejet56 , I’m facing the same issue.

Could be wrong but I think when you’re reflecting you are sometimes getting trapped the collider you are reflecting off of. Not too long ago i got a similar but not exact problem and the solution was to start your raycast a little bit in the direction of reflection from where you reflected. Perhaps a look at the answer in my question from a few days ago could help you a little. https://answers.unity.com/questions/1690411/help-with-reflecting-in-2d.html?childToView=1690554#comment-1690554