line render - draw line

Hi there, I've searched the forum but haven't found a reasonable answer.

I would like to know, how to create and manipulate a LINE.

I would like to have that rendered in realtime in the main camera/game camera.

I would like to edit the endpoints of the line or have access to edit those positions, for example get the positions of 2 objects in 3d space and use them to create the line.

I would like to edit the colors and thicnkess of the line.

So, is that possible?

Thanks in advance,

You've basically just described the Line Renderer functionality built into Unity.

Docs for it are here.

See also Vectrosity, which is all about drawing lines. Also more info on the forum.

I had the same sort of issue (Unity doesn’t really document how to access the variables from a script), but here’s a little script I put together just to illustrate how this works (in javascript):

#pragma strict
var vertexList = new Array();
var lr : LineRenderer;
function Start () {
    vertexList.push(Vector3(0, 0, 0));
    vertexList.push(Vector3(2, 4, 0));
    vertexList.push(Vector3(4, 0, 0));
    lr.SetVertexCount(vertexList.length);
    for(var i=0; i<vertexList.length; i++){
        lr.SetPosition(i, vertexList*);*

}
}
Basically just populates an array of Vector3s and sets them as the Line Renderers’s vertices, then draws them.
Hope this helps.

void DrawLine(Vector3 start, Vector3 end, Color color, float duration = 0.2f)
{
GameObject myLine = new GameObject();
myLine.transform.position = start;
myLine.AddComponent();
LineRenderer lr = myLine.GetComponent();
lr.material = new Material(Shader.Find(“Particles/Alpha Blended Premultiply”));
lr.SetColors(color, color);
lr.SetWidth(0.1f, 0.1f);
lr.SetPosition(0, start);
lr.SetPosition(1, end);
GameObject.Destroy(myLine, duration);
}