I'm creating a game similar to the colour switch game, I've created this script to generate a random colour combination out of 8 colours. I've split my wheel into 4 parts. I want each part to have a different colour when I press the button, however, after many attempts, I'm still getting my issue of two or more parts having the same colour. Can this be done?
(In the example, I click the button 5 times, in two cases, the same colour repeated twice, aka the purple and the pink.)
My code:
public SpriteRenderer[] colorWheels;
public Color[] colorcombination;
public int uniqueRandomInt(int min, int max)
{
int result = Random.Range(min, max);
if(result == lastRandomNumber) {
return uniqueRandomInt(min, max);
}
lastRandomNumber = result;
return result;
}
public void switchColour()
{
for(int i = 0; i < colorWheels.Length; i ++)
{
colorWheels[i].material.color = RANDcolorcombination[uniqueRandomInt(0,8)];
}
}
Thank you!