I know how to access an array from another script. I’m pretty sure I know the answer to this, but want to be sure: am I accessing a copy of that array, or a reference to it? What if that array is changed?
Ex (both scripts on same object):
class ClassA {
Color32[] colors;
void Start {
colors = new Colors32[640*480];
}
Update() {
// change colors
foreach (c in colors)
c = RandomColor();
// or REALLY change colors
colors = someTexture.GetPixels();
}
}
now in another class I want to get at the CURRENT ‘colors’ array.
class ClassB {
ClassA A; // will set with Inspector
void Update() {
Analyze (A.colors); // the CURRENT color array from object A
}
}
So, what will A.colors be in classB’s Update? Ideally what I want is a reference to that array so I can read/write it, no matter what it happens to be, like a reference or C pointer-to-pointer.