Answers for "unity random color"

C#
6

unity generate random color

//using Color
Color randomColor = new Color(
	Random.Range(0f, 1f), //Red
	Random.Range(0f, 1f), //Green
	Random.Range(0f, 1f), //Blue
	1, //Alpha (transparency)
);

//using Color32
Color32 randomColor = new Color32(
	Random.Range(0, 255), //Red
	Random.Range(0, 255), //Green
	Random.Range(0, 255), //Blue
	255, //Alpha (transparency)
);
Posted by: Guest on May-06-2020
2

unity random color

// Pick a random, saturated and not-too-dark color
GetComponent<Renderer>().material.color = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);
Posted by: Guest on May-13-2021
1

get random color 32

private Color32 GetRandomColour32()
{
    //using Color32
    return new Color32(
      (byte)UnityEngine.Random.Range(0, 255), //Red
      (byte)UnityEngine.Random.Range(0, 255), //Green
      (byte)UnityEngine.Random.Range(0, 255), //Blue
      255 //Alpha (transparency)
    );
}
Posted by: Guest on December-07-2020
2

set object to random color unity

[RequireComponent(typeof(Renderer))]
public class colorTint : MonoBehaviour
{
    public List<Color> TintColors;
    // Start is called before the first frame update
    void Start()
    {

            Color c = TintColors[Random.Range(0, TintColors.Count)];

            GetComponent<Renderer>().material.color = c;
    }
Posted by: Guest on June-12-2020

C# Answers by Framework

Browse Popular Code Answers by Language