# How can I draw a rectangle with a color gradient?

I'm trying to implement below picture in my code but doesn't work. It only shows red color on all sides. I'm using line renderer and color gradient. Kindly check my code. Thanks in advanced

void Start()
{
lineGeneratorPrefab = new GameObject();

DrawLine();
}

private void DrawLine()
{
GameObject myLine = new GameObject();
myLine.transform.position = start;
lr = myLine.GetComponent<LineRenderer>();
lr.positionCount = 4;
lr.SetPosition(0, new Vector3(-2, 0, 0));
lr.SetPosition(1, new Vector3(2, 0, 0));
lr.SetPosition(2, new Vector3(2, -2, 0));
lr.SetPosition(3, new Vector3(-2, -2, 0));
lr.loop = true;

{
},
);

}


The problem is that you have set the time parameter of all four of you GradientColorKey to .25f so it will only apply the first color.

Just change it to something like this

gradient.SetKeys(