Hi everyone, I’m having a bit of an issue and right when I thought I figured it out I have a problem. I’m making a game that allows you to pick from 30 randomly-colored icons.
Here is an array of colors I’ve created:
public Color[] avatarColors = new Color[9];
void Start () {
avatarColors [0] = new Color (255/255f, 130/255f, 171/255f); //palevioletred1
avatarColors [1] = new Color (218/255f, 112/255f, 214/255f); //orchid
avatarColors [2] = new Color (131/255f, 111/255f, 255/255f); //slateblue1
avatarColors [3] = new Color (100/255f, 149/255f, 237/255f); //cornflowerblue
avatarColors [4] = new Color (174/255f, 238/255f, 238/255f); //paleturquoise2
avatarColors [5] = new Color (152/255f, 251/255f, 152/255f); //palegreen
avatarColors [6] = new Color (154/255f, 205/255f, 50/255f); //olivedrab3
avatarColors [7] = new Color (240/255f, 230/255f, 140/255f); //khaki
avatarColors [8] = new Color (255/255f, 193/255f, 37/255f); //goldenrod1
}
Now, making my GUILayout use these colors should be simple, here is my attempt:
for (int i = 0; i < 3; i++) {
GUILayout.BeginHorizontal ();
GUILayout.FlexibleSpace ();
for (int j = 0; j < 10; j++){
GUI.contentColor = avatarColors[Random.Range (0, avatarColors.Length)];
if(GUILayout.Button (avatarImage, faceplateStyle, GUILayout.Width (avatarWidth), GUILayout.Height(avatarHeight))){}
GUI.contentColor = preColor;
}
GUILayout.FlexibleSpace ();
GUILayout.EndHorizontal ();
GUILayout.Space (bufferSpace);
}
This successfully creates three rows of ten icons (30 items total) with random colors; however, the colors fluctuate constantly! I’m not sure how to assign the colors in a way that is both completely random, and that doesn’t change once it’s been set.
Thank you in advance to anyone who can help!