私はUnity3Dでの状態パターンを(私はUnityへのSUPER新たなんだ)をテストするには、次の3つのスクリプトを作成し、予期しない結果を得た:Unity3D:入れ替える子クラスのインスタンス(状態パターン)
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();
}
}
これをGameObjectに添付すると、コンソールに「Entered IntroState」が表示されます。代わりに、 "Entered BaseState"が表示されます。
私は間違っていますか?