Hello
I have a set of inherited classes and i want to cast my data depending on the data involved. So this is my setup currently:
public class Behaviour : Objects {
public Handler reference;
public Behaviour(int tx, int ty, Handler ref) : base (tx,ty){
reference = ref;
}
public Behaviour(int tx, int ty, Handler ref) : base (tx,ty){}
}
public class Behaviour2 : Objects {
public SpecialHandler reference;
public Behaviour2(int tx, int ty, SpecialHandler ref) : base (tx,ty) {
reference = ref;
}
}
public class SpecialHandler : Handler {
public Settings level {get;set;}
}
public class Handler : MonoBehaviour{
virtual public void Enter(List<Node> n,Vector3 p){}
virtual public void Exit(List<Node> n, Node curNode){}
}
And then i am trying to do something like this:
//need to set t here so i don't lose scope
??? temp;
if(myObjects[i] is Behaviour){
temp = (Behaviour)path[i];
} else if (data[i] is Behaviour2){
temp = (Behaviour2)path[i];
}
t.reference.Enter(result,position);
So the problem here is how do i set my type for temp before i assign it and then i can call the method ? They both will have access to .Enter method but i need to cast the type first so i have the correct reference.
Hope you can help explain as i am confused.