Hi guys, I got a question again,
I would like to know how or if you can fill an array of own classes in
the object inspector.
I got some classes, basically working like that:
class A{…}
class B : A{…}
class C : A{…}
and so on…
I then added public A Spellliste into the code for my gameobject.
I would like to add something like that:

My problem is, that I could fill the array with objects of A, but not with objects of B or C, even though they could be added via code.
Is there any way to work arround that problem?
thanks for any help!
1 Answer
1
I’m not sure I understand you 100%, but if this is what you’re trying to do, you could use something like the following (haven’t tested this code, just from memory):
using UnityEngine;
using System.Collections;
using System.Collections.Generic; // necessary for lists
public class Container : Monobehaviour
{
public List<ClassA> listA = new List<ClassA>();
public List<ClassB> listB = new List<ClassB>();
void Start()
{
listA.Add(new ClassA());
listB.Add(new ClassB());
}
}
[System.Serializable]
public class ClassA
{
//foo bar baz qux type stuff
}
[System.Serializable]
public class ClassB
{
}