Ejemplo n.º 1
0
    void OnMouseOver()
    {
        //Sets the cursor text to this object's name when hovered over
        cc.setCursorText(itemName);


        //On click...
        if (Input.GetMouseButtonDown(0))
        {
            if (canBeTaken)
            {
                TakeItem();
                //Set the description to be blank
                cc.setDescriptionText("");

                //if the object is destroyed when taken, destroy it. Otherwise, just make it so you can't take it again.
                if (destroyWhenTaken)
                {
                    cc.setCursorText("");
                    Object.Destroy(gameObject);
                }
                else
                {
                    canBeTaken = false;
                }
            }
            //if the user is trying to use an item on this object
            else if (inv.getSelectedItem() != null)
            {
                //if this interactable has no puzzles on it, then deselect the item and change description accordingly
                if (puzzles == null)
                {
                    inv.deselectItem();
                    cc.setDescriptionText("I can't use that here.");
                }
                else
                {
                    //check any puzzles on this object; if this item works with one of them, then end and move. Otherwise, set description accordingly.
                    bool worked = false;
                    for (int i = 0; i < puzzles.Length; i++)
                    {
                        if (puzzles[i].useItem(inv.getSelectedItem()))
                        {
                            worked = true;
                            break;
                        }
                    }

                    if (!worked)
                    {
                        inv.deselectItem();
                        cc.setDescriptionText("I can't use that here.");
                    }
                    else
                    {
                        inv.expendItem();
                        cc.setDescriptionText("I used the item!");
                    }
                }
            }
            //If this object can't be taken, put the description text in the box
            else
            {
                cc.setDescriptionText(description);
            }
        }
    }