ConnectCastesToGUI gets called once in Start. I'm getting IndexOutOfRangeException when ChangeColor triggers (ie, when the dropdown has its value changed). It thinks the casteIndex is 3?
public void ConnectCastesToGUI()
{
for (int i = 0; i < Castes.Length; i++)
{
Debug.Log("Connecting Caste " + i + " to ColorDropdown " + i);
MainGUIPanel.Instance.ColorDropdowns[i].onValueChanged.AddListener(delegate{ChangeColor(i);});
}
}
public void ChangeColor(int casteIndex)
{
Debug.Log("Attempting to change the color of Caste " + casteIndex + " to ");
int colorIndex = MainGUIPanel.Instance.ColorDropdowns[casteIndex].value;
Color color = PaletteManager.Colors[colorIndex];
for (int j = 0; j < AntCountByCaste[casteIndex]; j++)
{
Ant ant = AntsByCaste[casteIndex][j];
ant.Transform.GetChild(0).GetComponent<Renderer>().material.color = color;
}
}