This might be more of a C# than a Unity question and I can’t help but think the answer is staring me in the face buuuuttt…
Let’s say I have a Class A:
public abstract class ClassA : MonoBehaviour
{
public abstract List<Int> exampleList { get; set; }
}
And a class B:
public class ClassB : MAI_Module
{
public override List<Int> exampleList
{
get
{
return exampleList;
}
set
{
exampleList = new List<Int>();
exampleList.Add(1);
exampleList.Add(10);
exampleList.Add(100);
exampleList = value;
}
}
}
How can I create a new list for class B? (Please note the get/set in ClassB was just me trying things)
What I’m trying to do is this:
//This code is in a class C:
classes = new List<ClassA>();
//Get all the ClassA's on the gameObject:
foreach (ClassA a in gameObject.GetComponents<ClassA>())
{
classes.Add(a);
}
//Create a new list of all the Ints from all the ClassA exampleLists:
exampleList = new List<Int>();
foreach (ClassA a in classes)
{
foreach (Int number in a.exampleList)
{
exampleList.Add(number);
}
}
I just can’t seem to figure out how to create a new list in ClassB but still be able to get it from all the ClassA’s in ClassC (since ClassB is derived from ClassA).
Any help is appreciated, I can clarify my question if needed. Thanks ![]()