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 gameover
Answer by zero_null · Jan 01, 2018 at 08:36 AM
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.
still confusing can you share code thnx in advance @adnanpk
you need to tell what you have tried. And where and why you think you failed ?
Answer by jayesh4520 · Jan 02, 2018 at 01:34 AM
I tried but color are not changing (4 color random script) I found on Google @adnanpk
Answer by Phantom_101 · Jan 02, 2018 at 02:03 AM
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];
}