Hi everyone,
I’m trying to do something with a member of a class that I found in a list.
In my example, I want my characters (agent) to freak out (Panic()) when they are near a scary thing (panicSource). PanicSource is in fact derived from PanicObject: (I stripped out everything that I think isn’t part of my Problem).
public class PanicSource : PanicObject {
//[…]
public float scariness;
//[…]
}
panicObjects is an abstract list of all the PanicObjects. They register themselves.
public class PanicObject : MonoBehaviour {
//[…]
//static list of all the PanicObjects
public static List<PanicObject> panicObjects = new List<PanicObject>();
//constructor
public PanicObject(){
//add myself to the list
panicObjects.Add(this);
}
//[…]
}
and then, In my character class, I go through all the panicObjects and if they’re a a PanicSource, I want to do something.
//[…]
foreach (var thing in PanicObject.panicObjects) {
//… some checks for distance etc.
if (thing is PanicSource) {
agent.Panic (thing.scariness); //this is where my error is
}
}
//[…]
However, “scariness” apparently isn’t a member of the thing, (even though the previous check makes sure that the thing is a PanicSource which has that public member.
(error CS1061: Type
PanicObject' does not contain a definition for
scariness’ and no extension method
scariness' of type
PanicObject’
could be found. Are you missing an
assembly reference?)
Thanks in advance!