“}预期”然而支架就在那里

时间:2014-02-07 00:50:29

标签: c#

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。

3 个答案:

答案 0 :(得分:3)

您错过了}功能的结束Update。因此,所有其他大括号都不同步。

答案 1 :(得分: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;
                        }
            }   

你的结束支架在哪里....?尝试在底部添加一个支架

答案 2 :(得分:0)

你需要在最后添加另一个}。