unity c# random color code example
Example 1: unity generate random color
Color randomColor = new Color(
Random.Range(0f, 1f),
Random.Range(0f, 1f),
Random.Range(0f, 1f),
1,
);
Color32 randomColor = new Color32(
Random.Range(0, 255),
Random.Range(0, 255),
Random.Range(0, 255),
255,
);
Example 2: set object to random color unity
[RequireComponent(typeof(Renderer))]
public class colorTint : MonoBehaviour
{
public List<Color> TintColors;
void Start()
{
Color c = TintColors[Random.Range(0, TintColors.Count)];
GetComponent<Renderer>().material.color = c;
}