Exemplo n.º 1
0
    //when item in range and e button pressed
    void Update()
    {
        if (Input.GetButtonDown("Interact") && currentInterObj)
        {
            //Check to see if this item is to be added in inventory
            if (currentInterObjScript.inventory)
            {
                //sends it to inventory script and add to inventory
                inventory.AddItem(currentInterObj);
            }

            //check to see if this object can be opened
            if (currentInterObjScript.openable)
            {
                //check to see if object is locked
                if (currentInterObjScript.locked)
                {
                    //check to see if we have object needed to unlock
                    //search inventory for the item needed. if found unlock object
                    if (inventory.FindItem(currentInterObjScript.itemNeeded))
                    {
                        //we found the item needed
                        currentInterObjScript.locked = false;
                        Debug.Log(currentInterObj.name + "Was unlocked");
                    }
                    else
                    {
                        Debug.Log(currentInterObj.name + "was not unlocked");
                    }
                }
                else
                {
                    //object is not locked- open the object
                    Debug.Log(currentInterObj.name + "is unlocked");
                    //call open door animator method
                    //currentInterObjScript.Open ();
                }
            }

            //chek to see if this object talks and has a message
            if (currentInterObjScript.talks)
            {
                //tell the object to give its message
                currentInterObjScript.Talk();
            }
        }
        //use a Potion
        if (Input.GetButtonDown("Use Potion"))
        {
            //Check the inventory for a potion
            GameObject potion = inventory.FindItemByType("Health Potion");
            if (potion != null)
            {
                //use the potion- apply effect

                //remove the potion from inventory
                inventory.RemoveItem(potion);
            }
        }
    }
Exemplo n.º 2
0
    void Update()
    {
        #region SECTION: INTERACTION
        if (Input.GetButtonDown("Interact") && currentInterObj && !UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
        {
            #region SECTION: INVENTORY
            //Check to see if this object is to be stored in inventory
            if (currentInterObjScript.inventory)
            {
                inventory.AddItem(currentInterObj);
            }
            #endregion
            #region SECTION: OPENABLE OBJECTS
            //Check to see if this object can be opened
            if (currentInterObjScript.openable)
            {
                //Check to see if the object is locked
                if (currentInterObjScript.locked)
                {
                    //Check to see is we have the object needed to unlock
                    //Search the inventory for the item needed - if found, unlock object
                    if (inventory.FindItem(currentInterObjScript.itemNeeded))
                    {
                        //We found the item needed
                        currentInterObjScript.locked = false;
                        Debug.Log(currentInterObj.name + " was unlocked");
                    }
                    else
                    {
                        Debug.Log(currentInterObj.name + " was not unlocked");
                    }
                }
                else
                {
                    //Object is not locked - open the object
                    Debug.Log(currentInterObj.name + " is unlocked");
                    currentInterObjScript.Open();
                }
            }
            #endregion
            #region SECTION: TALKING OBJECTS + DO THEY HAVE A MESSAGE?
            if (currentInterObjScript.talks)
            {
                //tell the object to give its message
                currentInterObjScript.Talk();
            }
            #endregion
        }
        #endregion

        #region SECTION: USING ITEMS
        ////Use a potion
        //if (Input.GetButtonDown("Use Potion"))
        //{
        //    //Check inventory for a potion
        //    GameObject potion = inventory.FindItemByType("Health Potion"); //If you said the itemType was a health potion in unity
        //    if (potion != null)
        //    {
        //        //Use the potion - apply its effect

        //        //Remove the potion from inventory
        //    }

        //}

        #endregion
    }