i want random color in my five block but not same color how i do that

i want random colour in my fuve block but not same colour how i do that and i want to compare that color with my player if color is same(player and block) then it will go if not then gameover108337-block.png

The simplest solution will be that you use a list of colors. When you assign a color keep it stored in the list and when you create a random new color just compare it with existing colors in your list. This way you only allow a random color to be part of your list and it won’t be repeated.

Kindly check the OnTriggerEnter2D for knowing about how the collisions and trigger work.

I tried but color are not changing (4 color random script)
I found on Google @adnanpk

You can do this:

public Color[] colors;

void Start () {
    GetComponent<MeshRenderer> ().material.color = ChooseRandomColor ();
}

Color ChooseRandomColor () {
    int randomInt = Random.Range (0, colors.Length);
    return colors[randomInt];
}