Looking for some advice on the best way to do something. I have a superclass (GridState), and subclasses from that class (GridStateFighter, GridStateArcher, etc.).
I want to have different gameobject units hold their own versions of GridState somehow. Then when the manager of GridState needs to change the subclass to use, it could reference that gameobject and instantiate that subclass. Wrote a quick example below. I could be totally off base on this, but I’d like something that doesn’t involve a massive if/else or similar as the subclasses grow. Any suggestions would be greatly appreciated.
class abstract GridState{}
public GridStateFighter :GridState{}
public GridStateArcher :GridState()
public abstract class Grid
{
public GridState _gridstate;
public OnFighter()
{
_gridState = new GridStateFighter ();
}
public OnArcher()
{
//Could just have one method if I am able to reference the subclass
somehow dynamically.
_gridState = new GridStateArcher ();
}
}