统一检查状态

时间:2015-06-04 10:08:54

标签: c# unity3d enums states

我希望以统一的方式为对象制作动画。首先,我想检查一下我的播放器状态。我不得不说我使用枚举来命名状态。 这是我检查状态的代码:

switch(PlayerStateController.playerStates)
    {
    case PlayerStateController.playerStates.idle:
        break;
    case PlayerStateController.playerStates.left:
        transform.Translate(new Vector3(-1.5f * Time.deltaTime, 0.0f, 0.0f));
        break;
    case PlayerStateController.playerStates.right:
        transform.Translate(new Vector3(1.5f * Time.deltaTime, 0.0f,
                                       0.0f));
        break;
    }

但我有一个错误:

  

表达式表示'类型'其中'变量''值'或者'方法组'预计

1 个答案:

答案 0 :(得分:0)

public class AnyClass {
    public enum PlayerState {
        idle,
        left,
        right
    }
}

-

public class AnyOtherClass {
    void DoStuff(PlayerState state) {
        switch (state) {
        case PlayerState.idle:
            break;
        case PlayerState.left:
            transform.Translate(new Vector3(-1.5f * Time.deltaTime, 0.0f, 0.0f));
            break;
        case PlayerState.right:
            transform.Translate(new Vector3(1.5f * Time.deltaTime, .0f, 0.0f));
            break;
        }
    }