Hello i am kinda confused how i set a public variable in an inherited class situation. I got methods working using virtual and override, but can’t see to get it to work for public variables.
My code has this structure:
public class Node{ //generic applies to all
public int x;
public int y;
public Node(int tx, int ty){
x = tx;
y = ty;
}
}
public class BasicAsset : Node{ // basic assets with no unique behaviour
public Actions actions;
public Asset(int x, int y, Actions a) : base (x,y) {
actions = a;
}
}
public class PlatformAsset : Node { //unique to platforms
public PlatformHandler handler;
public Asset(int x, int y, PlatformHandler h) : base (x,y) {
handler = h;
}
}
public class Actions : MonoBehaviour{ //generic applies to all
virtual public void Enter(List<Node> n,Vector3 p){}
virtual public void Exit(List<Node> n, Node curNode){}
}
public class PlatformHandler : Actions { //unique to platforms
virtual public Platform platform {get; set;}
}
In my class PlatformHandler i want to set the Platform to a list i have. First the platform component which has an error and looks like this:
public class PlatformController : PlatformHandler {
//ERROR: The modifier `override' is not valid for this item - Why?
override public Platform platform;
}
As you can see i get an error for using override here - so am a bit confused why.
Here is a code snippet in my game which is meant to be setting platforms to a list:
Platform platform = go.GetComponent<Platform>();
for(int i=0;i<platformAreas.Count;i++){
PlatformAsset asset = (PlatformAsset)platformAreas[i];
platformAsset.handler.platform = platform;
}
So yeah what is the correct syntax for this ? It works fine for my methods in Actions but not a variable. Hope you can help explain my error.