【问题标题】:only assignment call increment decrement and new object expressions can be used as a statement只有赋值调用自增自减和新对象表达式可以作为语句使用
【发布时间】:2016-07-21 17:40:04
【问题描述】:

我正在 Unity 中制作游戏,但我不知道为什么会出现此错误。如果你们能帮助我,我将不胜感激。

private enum States
{
    NewGame,
    Cell,
    Sheets, 
    Mirror, 
    Lock, 
    Key, 
    Escape
}

private States my_state;

void state_cell()
{
    text.text = "You are in a jail captured by Indians, you have to escape at all cost. You have to " +
                "aware the Pakistan Army about the evil plans of indians, and you got minimal time left " +
                "\n\n Press S to view the Sheets, press R to return, Press M to get the Mirror,press " +
                "L to view the Lock, and press M to make Key";
    if(Input.GetKeyDown(KeyCode.S))
    {
        (my_state = States.Sheets);
    }
}
void state_sheets()
{
    text.text = "Press S to view the sheets which has info about the security lock, There is some wet " +
                "mud and a metal things lying around see if you can make a key for the Lock " +
                "Also you wanna cut some piece from the Mirror hanging on the wall to find the " +
                "measurements of the Lock";

    if(Input.GetKeyDown(KeyCode.R))
    {
        (my_state = States.Cell);
    }
}

我也在使用 monodevelop 4.0.1 版

【问题讨论】:

    标签: c#


    【解决方案1】:

    你这里的括号没用,导致编译错误:

    (my_state = States.Sheets);
    

    这样就可以了:

    my_state = States.Sheets;
    

    仅在某些情况下允许使用括号,例如 if ()((CastTo)a) 语句。这不是其中一种情况:不要在作业周围加上括号。

    【讨论】:

      【解决方案2】:

      (my_state = States.Sheets) 等周围的括号是问题所在,因为它们正在执行分配然后返回一个值,在这种情况下将是分配的值。编译器不明白在这里做什么——就像有一行代码写着123;

      【讨论】:

        猜你喜欢
        • 2018-11-13
        • 1970-01-01
        • 2019-08-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-27
        • 1970-01-01
        相关资源
        最近更新 更多