2016-12-08 54 views
-2

嘿堆垛我得到了在C#中的IM幾個錯誤寫一個統一的遊戲 的錯誤是:團結3D錯誤C#

}預期(約3倍)

類型命名空間定義或文件結束預期(1次)

可能誤認爲空語句(2次)

無效表達術語 '> ='(1次)

不能隱式轉換型「浮動」到「布爾」(1次)

「對象」不包含「Runspeed」的定義,並沒有擴展方法「runspeed」接受類型的第一個參數「對象」可以找到(是否缺少using指令或程序集引用?)(1次)

using UnityEngine; 
using System.Collections; 
using UnityEngine.UI; 

public class Playervitals : MonoBehaviour 
{ 
    public Slider healthslider; 
    public int maxHealth; 
    public int healthFallRate; 

    public Slider thirstslider; 
    public int maxThirst; 
    public int thirstFallRate; 

    public Slider hungerslider; 
    public int maxHunger; 
    public int hungerFallRate; 

    public Slider staminaslider; 
    public int maxstamina; 
    public int staminaFallRate; 
    public int staminaFallMult; 
    private int staminaRegainRate; 
    public int staminaRegainMult; 

    private CharacterController charcontroller; 
    private FPSInputController playercontroller; 

    void Start() 
    { 
     healthslider.maxValue = maxHealth; 
     healthslider.value = maxHealth; 

     thirstslider.maxValue = maxThirst; 
     thirstslider.value = maxThirst; 

     hungerslider.maxValue = maxHunger; 
     hungerslider.value = maxHunger; 

     staminaslider.maxValue = maxstamina; 
     staminaslider.value = maxstamina; 

     staminaFallRate = 1; 
     staminaRegainRate = 1; 
     charcontroller = GetComponent<CharacterController>(); 
     playercontroller = GetComponent<FPSInputController>(); 
    } 

    void Update() 
    { 
     //HEALTH CONTROL SECTION 
     if (hungerslider.value <= 0 && (thirstslider.value <= 0)) 
     { 
      healthslider.value -= Time.deltaTime/healthFallRate * 2; 
     } 

     else if (hungerslider.value <= 0 || thirstslider.value <= 0) 
     { 
      healthslider.value -= Time.deltaTime/healthFallRate; 
     } 

     if (healthslider.value <= 0) 
     { 
      CharacterDeath(); 
     } 

     //HUNGER CONTROL SECTION 
     if (hungerslider.value >= 0) 
     { 
      hungerslider.value -= Time.deltaTime/hungerFallRate; 
     } 

     else if (hungerslider.value <= 0) 
     { 
      hungerslider.value = 0; 
     } 

     else if (hungerslider.value >= maxHunger) 
     { 
      hungerslider.value = maxHunger; 
     } 

     //THIRST CONTROL SECTION 
     if (thirstslider.value >= 0) 
     { 
      thirstslider.value -= Time.deltaTime/thirstFallRate; 
     } 

     else if (thirstslider.value <= 0) 
     { 
      thirstslider.value = 0; 
     } 

     else if (thirstslider.value >= maxThirst) 
     { 
      thirstslider.value = maxThirst; 
     } 
     //Staminacontroller 

     if (charcontroller.velocity.magnitude > 0 && Input.GetKey(KeyCode.LeftShift)) ; 
     { 

      staminaslider.value -= Time.deltaTime/staminaFallRate * staminaFallMult; } 






     else 
     { 
      staminaslider.value += Time.deltaTime/staminaRegainRate * staminaRegainMult; 
      } 

     if (staminaslider.value >= maxstamina) 

     { 
      staminaslider.value = maxstamina; 
     } 
     else if (staminaslider.value <= 0) ; 

     { 
      staminaslider.value = 0; 
       { 
        staminaslider.value = 0; 
        playercontroller.m.Runspeed = playercontroller.m_walkspeed; } 


        else if (staminaslider.value) >= 0;); 
      { 
       } 
       playercontroller.m_runspeed = playercontroller.m_runspeednorm; 

      } 

     } 
    } 

    void CharacterDeath() 
    { 
     //DEATH 
    } 
} 

我希望你們能幫助我:)

+2

您的代碼(後半段)是...呃...充滿了語法錯誤。 if語句之後的分號,孤立的大括號......你確定你不想再一次查看它了嗎? (Typos不是堆棧溢出的主題問題,因爲它們對未來的讀者有限制/沒有價值。) – Serlite

+0

我知道的人,但聞一加布萊希特和刪除他,我得到88級的錯誤,而不是8:P。 – Matthias

+0

檢查'如果(charcontroller.velocity.magnitude>'線和下面的'if'聲明不應該有一個';'後,如果您應該,但''{在一個新行'否則,如果(staminaslider.value <= 0)後,用分號一樣;',它刪除那麼爲什麼你打開另一''在'staminaslider.value = 0;'後的代碼後面加上'';''刪除它們。 –

回答

0

是的,這大概這樣做,所有這些東西。

using UnityEngine; 
using System.Collections; 
using UnityEngine.UI; 

public class Playervitals : MonoBehaviour 
{ 
    public Slider healthslider; 
    public int maxHealth; 
    public int healthFallRate; 

    public Slider thirstslider; 
    public int maxThirst; 
    public int thirstFallRate; 

    public Slider hungerslider; 
    public int maxHunger; 
    public int hungerFallRate; 

    public Slider staminaslider; 
    public int maxstamina; 
    public int staminaFallRate; 
    public int staminaFallMult; 
    private int staminaRegainRate; 
    public int staminaRegainMult; 

    private CharacterController charcontroller; 
    private FPSInputController playercontroller; 

    void Start() 
    { 
     healthslider.maxValue = maxHealth; 
     healthslider.value = maxHealth; 

     thirstslider.maxValue = maxThirst; 
     thirstslider.value = maxThirst; 

     hungerslider.maxValue = maxHunger; 
     hungerslider.value = maxHunger; 

     staminaslider.maxValue = maxstamina; 
     staminaslider.value = maxstamina; 

     staminaFallRate = 1; 
     staminaRegainRate = 1; 
     charcontroller = GetComponent<CharacterController>(); 
     playercontroller = GetComponent<FPSInputController>(); 
    } 

    void Update() 
    { 
     //HEALTH CONTROL SECTION 
     if (hungerslider.value <= 0 && (thirstslider.value <= 0)) 
     { 
      healthslider.value -= Time.deltaTime/healthFallRate * 2; 
     } 

     else if (hungerslider.value <= 0 || thirstslider.value <= 0) 
     { 
      healthslider.value -= Time.deltaTime/healthFallRate; 
     } 

     if (healthslider.value <= 0) 
     { 
      CharacterDeath(); 
     } 

     //HUNGER CONTROL SECTION 
     if (hungerslider.value >= 0) 
     { 
      hungerslider.value -= Time.deltaTime/hungerFallRate; 
     } 

     else if (hungerslider.value <= 0) 
     { 
      hungerslider.value = 0; 
     } 

     else if (hungerslider.value >= maxHunger) 
     { 
      hungerslider.value = maxHunger; 
     } 

     //THIRST CONTROL SECTION 
     if (thirstslider.value >= 0) 
     { 
      thirstslider.value -= Time.deltaTime/thirstFallRate; 
     } 

     else if (thirstslider.value <= 0) 
     { 
      thirstslider.value = 0; 
     } 

     else if (thirstslider.value >= maxThirst) 
     { 
      thirstslider.value = maxThirst; 
     } 
     //Staminacontroller 

     if (charcontroller.velocity.magnitude > 0 && Input.GetKey(KeyCode.LeftShift)) //; < extra semicolon here 
     { 

      staminaslider.value -= Time.deltaTime/staminaFallRate * staminaFallMult; 
     } 
     else 
     { 
      staminaslider.value += Time.deltaTime/staminaRegainRate * staminaRegainMult; 
     } 

     if (staminaslider.value >= maxstamina) 

     { 
      staminaslider.value = maxstamina; 
     } 
     else if (staminaslider.value <= 0)// ; extra here as well 

     { 
      staminaslider.value = 0; 
      //{ extra 
      //staminaslider.value = 0; duplicate 
      playercontroller.m.Runspeed = playercontroller.m_walkspeed; 
     } 
     // then else makes sense here 

     else if (staminaslider.value/* get rid of this) */ >= 0) // get rid of this ;); 
     { 
     } 
     playercontroller.m_runspeed = playercontroller.m_runspeednorm; 

     //} extra 

    } 
    // had to move this into the class 
    void CharacterDeath() 
    { 
     //DEATH 
    } 
} 
// extra} 

你不把分號在結束if語句

if (true) ; { }錯誤

if (true) { }正確

你不把分號裏面的if語句

if (true;) { }錯誤

if (true) { }正確

讓我們來看看這一個在上面

else if (staminaslider.value) >= 0;);

太多的光)

而且;內,並在年底的if語句

此外,類的方法需要在該類中定義。另外,方法必須在類中。你有

class Playervitals 
{ 
} 
void CharacterDeath() 
{ 
    //DEATH 
} 
} 

正如你所看到的,太多的}和該方法是在一個類之外。

應該

class Playervitals 
{ 
    void CharacterDeath() 
    { 
     //DEATH 
    } 
}