C# 开关语法错误

标签 c# switch-statement syntax-error

我有这个 switch 语句来测试我的 Grounded 整数变量的大小写,但我的 Unity-Monodelop 说我的代码中有我找不到的奇怪语法错误。我希望有人能告诉我它有什么问题。

private void JumpController () {
    if (Input.GetAxis("Jump")) { // if jump switch to action
        switch (Grounded) {
        0:  // On ground;
            Jump ();
            Grounded = 1;
            break;
        1:  // Jumped once;
            Jump ();
            Grounded = 2;
            break;
        2:  // Jumped twice;
            Debug.print ("Grounded = 2");
            break;
        default: break; 
        }
    }
}

An Image showing the errors

最佳答案

我建议在您的案例之前添加一个案例。这应该可以修复错误:

private void JumpController () {
    if (Input.GetAxis("Jump")) { // if jump switch to action
        switch (Grounded) {
        case 0:  // On ground;
            Jump ();
            Grounded = 1;
            break;
        case 1:  // Jumped once;
            Jump ();
            Grounded = 2;
            break;
        case 2:  // Jumped twice;
            Debug.print ("Grounded = 2");
            break;
        default: break; 
        }
    }
}

关于C# 开关语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39559807/

相关文章:

c# - 我如何在 c# 或 vb.net 中向图像添加文本

c# - 有没有借口从隐式转换中抛出异常?

c++ - 没有默认标签的 Switch-Case 中的无效值

SWITCH 案例的 PHP 替代文本

rspec - page.should have_content - 导致错误的特殊字符

javascript - 如何将对象列表从 View 中的 javascript 代码传递到 Controller 中的操作方法

c# - 禁用 LinkBut​​ton 不会禁用 javascript 中的点击事件

android - 如何更改 ListView 中一行内状态的开关状态 - React Native

powershell - 需要帮助弄清楚为什么Powershell会引发错误16

haskell - 测量二叉树大小的函数