Hello, I have a problem that I don’t know how to reference a child class variable.
I have a scriptable object parent class
public abstract class parentClass : ScriptableObject
{
}
and a child class of this parent class
public class childClass : parentClass
{
public int value;
}
I got a list of parentClass classes and I want to ask the parentClass if it is a childClass and if it is a childClass get the variable value from it. How to get a reference to the childClass variable?
List<parentClass> list;
void Start() {
foreach (parentClass p in list) {
if (p is childClass c) {
print($"{c.name} is a childClass with value {c.value}");
}
}
}