Hi,
Strange question, but I’m new to C# and I’m trying to differentiate between the two blocks of code.
So, this:
public List<Color> shapeColor = new List<Color>();
if(shapeColor.Count > 0)
{
int newColor = Random.Range(0, shapeColor.Count);
renderer.material.color = shapeColor[newColor];
}
And this:
public Color[] shapeColor;
if(shapeColor.Length > 0)
{
int newColor = Random.Range(0, shapeColor.Length);
renderer.material.color = shapeColor[newColor];
}
Both blocks seem to achieve the same thing - selecting a random colour from an array of colours selected in the inspector. My understanding of C# was that you should use List<> if the array of items you’re using is not a set length as it will produce errors otherwise. Here, the colours are picked in the Inspector window, so it can’t be defined in the code.
I had initially defined the shapeColor array as below:
public Color shapeColor[];
But ran into errors with the rest of the code because of the above. My question is, how is using Color any different and is could this cause any difficulties?