2014-02-07 21 views
-5
using UnityEngine; 
using System.Collections; 
using System.Collections.Generic; 


public class Looting : MonoBehaviour 
{ 

    private Rect inventoryWindowRect = new Rect (300, 100, 400, 400); 
    private bool inventoryWindowShow = false; 

    private Dictionary<int, string> lootDictionary = new Dictionary< int, string>() 
    { 
     {0, string.Empty}, 
     {1, string.Empty}, 
     {2, string.Empty}, 
     {3, string.Empty}, 
     {4, string.Empty}, 
     {5, string.Empty}, 
     {6, string.Empty}, 
     {7, string.Empty}, 
     {8, string.Empty} 
    }; 

    ItemClass itemObject = new ItemClass(); 

    private Ray mouseRay; 
    private RaycastHit rayHit; 

    // Use this for initialization 
    void Start() 
    { 
     //display dictionary 
     lootDictionary[0] = itemObject.arrowItem.name; 
     lootDictionary[1] = itemObject.breadItem.name; 
    } 

    // Update is called once per frame 
    void Update() 
    { 

     mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); 

     if (Input.GetButtonDown("Fire1")) 
     { 
      Physics.Raycast(mouseRay, out rayHit);  
      if (rayHit.collider.transform.tag == "lootable corpse") 
      { 
       inventoryWindowShow = true; 
      } 
      // Closes loot window 
      if (Input.GetButtonDown(KeyCode.I)) 
      { 
       inventoryWindowShow = false; 
      } 
     } 


    void OnGUI() 
    { 

     if (inventoryWindowShow) 
     { 
      inventoryWindowRect = GUI.Window(0, inventoryWindowRect, inventoryWindowMethod, "corpse"); 
     } 
    } 

    void inventoryWindowMethod (int WindowId) 
    { 

     GUILayout.BeginArea(new Rect(0, 50, 400, 400)); 

     GUILayout.BeginHorizontal(); 

     if (GUILayout.Button(lootDictionary[0], GUILayout.Height (50))) 
     { 
      if (lootDictionary[0] != string.Empty) 
      { 
       InventoryGUI.inventoryNameDictionary[0] = lootDictionary[0]; 
       lootDictionary [0] = string.Empty; 
      } 
     } 

     if (GUILayout.Button(lootDictionary[1], GUILayout.Height(50))) 
     { 
      if (lootDictionary[1] != string.Empty) 
      { 
       InventoryGUI.inventoryNameDictionary[1] = lootDictionary[1]; 
       lootDictionary [1] = string.Empty; 
      } 
     } 

     if (GUILayout.Button(lootDictionary[2], GUILayout.Height(50))) 
     { 
      if (lootDictionary[2] != string.Empty) 
      { 
       InventoryGUI.inventoryNameDictionary[2] = lootDictionary[2]; 
       lootDictionary[2] = string.Empty; 
      } 
     } 

     GUILayout.EndHorizontal(); 

     GUILayout.EndArea(); 
    } 
} 

問題是行51.任何想法如何糾正它? 「}預期的」錯誤我已經嘗試了許多事物的組合。我也試過評論這個區塊,但沒有任何反應。我正在試圖爲一款遊戲搶劫系統。使用統一3D。「}預計」然而支架有

+4

您可以在第51行添加評論嗎? –

+3

告訴我們行號沒有行號沒有幫助。 –

回答

3

您錯過了Update函數的關閉}。因此,所有其他大括號都不同步。

+0

你擊敗了我5秒! :) –

+1

你也打敗了我。這就像競爭在哪裏沃爾多 – cost

0
// Update is called once per frame 
    void Update() { 

     mouseRay = Camera.main.ScreenPointToRay (Input.mousePosition); 

     if (Input.GetButtonDown ("Fire1")){ 
       Physics.Raycast (mouseRay, out rayHit);  
       if (rayHit.collider.transform.tag == "lootable corpse") 
        { 
         inventoryWindowShow = true; 
        } 
       // Closes loot window 
       if (Input.GetButtonDown(KeyCode.I)){ 
         inventoryWindowShow = false; 
         } 
      } 

你的右括號在哪裏....?嘗試在底部添加一個支架

0

您需要在最後添加另一個}。

+1

這並沒有提供一個問題的答案。要批評或要求作者澄清,請在其帖子下方留言。 – JasonMArcher

+0

這是問題的答案。 – javasocute