只有赋值调用增量递减和新对象表达式才能用作语句

时间:2016-07-21 09:14:38

标签: c#

我在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

2 个答案:

答案 0 :(得分:2)

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

(my_state = States.Sheets);

这样做:

my_state = States.Sheets;

仅在许多情况下允许使用括号,例如使用if ()((CastTo)a)语句。这不是其中一种情况:不要在括号内添加括号。

答案 1 :(得分:2)

围绕(my_state = States.Sheets)等的括号是问题所在,因为它们正在执行赋值然后返回一个值,在这种情况下将是指定的值。编译器并不了解这里要做什么 - 它就像有一行代码123;