2016-09-18 44 views
0

我有這個switch語句來測試我的接地整型變量的情況,但我的Unity-Monodevelop說我在我的代碼中有奇怪的語法錯誤,我找不到。我希望有人能告訴我它有什麼問題。C#開關語法錯誤

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

+0

情況下,x:? ...... – StuartLC

+1

您錯過了'case'關鍵字。例如'case 0:Jump();' –

回答

1

我會建議將您的案件之前case。這應該修復錯誤:

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; 
     } 
    } 
} 
+0

謝謝我不能相信我錯過了,即使我使用的結構指南有他們,但我只是忽略了他們。修復這個錯誤我終於得到了真正的錯誤,這是我的if語句。 –

+0

記住標記答案是正確的嗎?它使其他人更容易找到答案。 –

+0

當然可以。我希望我做對了 - 這個網站有點混亂,第一次作爲一個真正的用戶使用,而不僅僅是來自谷歌的參考。 –