Array of colors not working, all sprites turn white.

I’m sure there’s a simple solution for this, but I’m a total noob to code.

I’m trying to assign sprites with a random color from an array.

private Color[] colors = new Color[6];

void Start(){

		colors[0] = new Color(87f, 156f, 236f);
		colors[1] = new Color(246f, 108f, 108f);
		colors[2] = new Color(87f, 113f, 236f);
		colors[3] = new Color(240f, 78f, 74f);
		colors[4] = new Color(87f, 212f, 236f);
		colors[5] = new Color(131f, 112f, 208f);

		SpriteRenderer temp = GetComponent<SpriteRenderer>();
		if( temp == null )
		Debug.Log("fuck");
		temp.color = colors[Random.Range(0, colors.Length)];

}

(It also doesn’t work if I take out the conditional statement)

Appreciate all help as always :slight_smile:
Thanks :slight_smile:

Color: values between 0.0f and 1.0f
Color32: values between 0 and 255

You are setting all values of your Color higher than 1.0f, so it becomes white. Divide all values by 255.0f or use Color32 (with int).