什么可以导致IF语句在FALSE返回时仍然触发?

时间:2015-09-11 05:54:08

标签: c# if-statement xna xna-4.0 monogame

我在c#中为XNA MonoGame写作,并编写了一个敌人状态枚举,以便我可以确定在每个更新函数中用于敌人的逻辑。

这是枚举:

    public enum EnemyState {
                            /// <summary>Non-active state, ideally should not process logic.</summary>
                            WaitOrder,
                            /// <summary>Enemy is moving towards a directed position.</summary>
                            MoveOrder,
                            /// <summary>Enemy is chasing a directed target.</summary>
                            ChaseOrder,
                            /// <summary>Enemy is launching an attack towards directed target.</summary>
                            AttackOrder,
                            /// <summary>Enemy is dieing, and should be moving towards being deleted.</summary>
                            Dieing
                        }

我只是在我的敌人类中使用EnemyState state减速,构造函数添加state = EnemyState.MoveOrder

问题是,XNA对MoveOrder状态显得非常紧贴。即使我在进入移动更新功能之前检查state == EnemyState.MoveOrder,并且显然返回false,它仍会进入。

在移动函数内部有一个断点,标记我改变状态值的行,我逐行逐步执行代码。

Visual Studio在if语句之前和之后告诉我state == EnemyState.WaitOrderstate == EnemyState.MoveOrder返回false

什么可能导致它忽略这个要求,并跳进声明,即使没有满足要求?

As you can see, at the first line of the if statement, the if clause returns false.

更新

如果我将支票放入布尔值,首先,布尔值显示支票为真。也就是说,如果我将state == EnemyState.WaitOrder更改为state == 0,我就没有问题。

0 个答案:

没有答案