Line renderer color not working

This is my script for my line renderer

#pragma strict


var startWidth = 0.1;
var endWidth = 0.1;
var startColor : Color;
var endColor : Color;

private var Frog : GameObject;
private var Cylinder : GameObject;
private var line : LineRenderer;
 
function Start () {
 
    Cylinder = GameObject.Find("Cylinder (1)");
    Frog = GameObject.Find("EMPTY FROGGY");
 
;
    var lineObject = new GameObject("Line");
    line = lineObject.AddComponent(LineRenderer);
    line.SetWidth(startWidth, endWidth);
    line.SetColors(startColor, endColor);
    line.SetVertexCount(2);
}
 
function Update ()
{
    line.SetPosition(0, Frog.transform.position); 
    line.SetPosition(1, Cylinder.transform.position);
      line.SetColors(startColor, endColor);;
}

I have set the colors to green but it stays as pink no matter what. I have tried several things but none of them seem to be working…

Any help would be appreciated! Thanks :slight_smile:

Your lineRenderer doesn’t have a material. You should always check the API docs of you have problems with a function. The answer is right there :wink: LineRenderer.SetColors

     var lineObject = new GameObject("Line");
     line = lineObject.AddComponent(LineRenderer);
     line.material = new Material (Shader.Find("Particles/Additive"));
     line.SetWidth(startWidth, endWidth);
     line.SetColors(startColor, endColor);
     line.SetVertexCount(2);

Also it looks to me like your colors have their alpha value at 0 in the inspector so your line might be invisible after adding the material.