How to get a Line Render to shoot out from a ray?

Hey guys i was wondering if someone could help me i want to know how i can get a line render to shoot out from a ray and if it collides with something then become the length of the ray else remain the same.

thanks in advance

Interesting question. OK, if I understand correctly, you basically want to use a LineRenderer to visually represent a Raycast… I think this should do it:

var c1 : Color = Color.yellow;
var c2 : Color = Color.red;
var lineRenderer : LineRenderer;

function Start() {
     lineRenderer = gameObject.AddComponent(LineRenderer);
     lineRenderer.material = new Material (Shader.Find("Particles/Additive"));
     lineRenderer.SetColors(c1, c2);
     lineRenderer.SetWidth(0.2,0.2);
     lineRenderer.SetVertexCount(2);
}

function Update(){

var origin = transform.position;
var direction = transform.forward;
var endPoint = origin + direction * 100000;
var hit : RaycastHit;

lineRenderer.SetPosition(0, origin);

if (Physics.Raycast(origin,direction,hit))
endPoint = hit.point;

lineRenderer.SetPosition(1, endPoint);
}

Just attach this script to the object to be shooting the ray