Hi all, in an attempt to condense code I am trying to keep an array of GetComponents for an array of gameobjects that are updated every time the array of gameobjects is updated with getters/setters. Here’s how it would work in my head:
private GameObject[] _SomeGO = new _SomeGO[3];
public SomeScript[] SomeGOScripts = new SomeGOScripts[3];
public GameObject[] SomeGO [int location] {
get {return _SomeGO[location]};
set {
_SomeGO[location] = value;
if (_SomeGO[location] == null) {
SomeGOScripts[location] = null;
}
else {
SomeGOScripts[location] = value.GetComponent<SomeScript>() as SomeScript;
}
}
}
However, this errors tremendously (I don’t think SomeGO is done correctly, but I don’t know how else to capture ‘location’). Any ideas on how to properly use getters/setters with a C# array?