Rotate Gradient C#

Good Afternoon, I am trying to use a variable to rotate my gradient from 0 to 360 degrees clock wise so the user can control the gradients angle.

Current Code:

using UnityEngine;
using UnityEditor;
using System.Collections;

public class Sample : MonoBehaviour {

public float ColorAngle;
public Color32 StartColor;
public Color32 EndColor;

void Start(){
// Mesh Generation Code //
}

void Update(){

Vector3[] vertices = Vertices;
Color32[] colors = new Color32[vertices.Length];

int i = 0;
while (i < vertices.Length) {
colors _= Color32.Lerp(StartColor, EndColor, vertices*.y);*_

// vertices*.y sets the angle just need to switch it to variable ColorAngle //*
i++;
}
}
mesh.colors32 = colors;
}
Thanks, I would really love the help :slight_smile:

Try replacing the color assignment with:

colors <em>= Color32.Lerp(StartColor, EndColor, vertices<em>.y*Mathf.Sin(ColorAngle) + vertices_.x*Mathf.Cos(ColorAngle));_</em></em>

If ColorAngle is in degrees instead of radians then remember to multiply by Mathf.Deg2Rad before passing to Sin/Cos.