I created the following three scripts to test out the State pattern in Unity3D (I'm SUPER new to Unity) and got unexpected results:
BaseState
public class BaseState {
public void Enter()
{
Debug.Log("Entered BaseState");
}
}
IntroState
public class IntroState : BaseState {
public void Enter()
{
Debug.Log("Entered IntroState");
}
}
StateController
public class StateController : MonoBehavior {
private BaseState state;
void Start()
{
state = new IntroState();
state.Enter();
}
}
When I attach this to a GameObject, I expect to see "Entered IntroState" in the console. Instead, I see "Entered BaseState".
What am I doing wrong?