Ejemplo n.º 1
0
    void OnGUI()
    {
        Ray        ray = camera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, 6f) && hit.collider.gameObject.GetComponent <IsItem>())
        {
            // Select object
            selected = hit.collider.gameObject;

            // Tooltip
            IsItem item = selected.GetComponent <IsItem>();
            CalcToolTipSize(item.itemType);
            GUI.Box(new Rect(tooltipPos.x, tooltipPos.y, rectWidth, rectHeight), item.itemType.Name);
        }

        if (showInventory)
        {
            // For each row
            for (int x = 0; x < Inventory.Bag.GetLength(0); x++)
            {
                // For each column
                for (int y = 0; y < Inventory.Bag.GetLength(1); y++)
                {
                    if (Inventory.Bag[x, y] != null)
                    {
                        GUI.Label(
                            new Rect(y * 80, x * 80, 80, 80),
                            Inventory.Bag[x, y].Graphic.texture
                            );
                    }
                }
            }
        }
    }
Ejemplo n.º 2
0
    public static GameObject DropItem(Item item)
    {
        GameObject nu = Resources.Load("Objects/ItemObject") as GameObject;
        IsItem     i  = nu.GetComponent <IsItem>();

        i.itemType = item;
        return(nu);
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonUp("Interact") && selected != null)
        {
            IsItem item = selected.GetComponent <IsItem>();
            if (!Inventory.AddItem(item.itemType))
            {
                Debug.Log("Inventory full");
                return;
            }
            ;
            Destroy(selected);
            selected = null;
        }

        if (Input.GetKeyUp(KeyCode.I))
        {
            showInventory = !showInventory;
        }
    }