At the beginning of my script I have this line:
Color[] oldColor;
Later I want to fill it with elements so in a function I wrote:
for (int i = 0; i < targets.Length; i++)
oldColor[i] = targets[i].color;
However, the first line is underlined in green and it says that I can't assign a value except from its default value (which is null). Also the line below the for loop (where it should copy the values from one array to the other) gives me NullReferenceException when I run it in Unity.
'targets' is defined as
SpriteRenderer[] targets;
All of its elements are assigned via the Inspector.
I don't understand what happens. Why doesn't it assign the variables?