unity get 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: unity random color
GetComponent<Renderer>().material.color = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);
Example 3: unity random color
using UnityEngine;public class ColorOnClick : MonoBehaviour
{
void OnMouseDown()
{
GetComponent<Renderer>().material.color = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);
}
}
Example 4: get random color 32
private Color32 GetRandomColour32()
{
return new Color32(
(byte)UnityEngine.Random.Range(0, 255),
(byte)UnityEngine.Random.Range(0, 255),
(byte)UnityEngine.Random.Range(0, 255),
255
);
}