Пример #1
0
    void Update()
    {
        if (Input.GetButtonDown("Interact") && currentInterObj)
        {
            // Check to see if this object is to be stored in inventory
            if (currentInterObjScript.inventory)
            {
                inventory.AddItem(currentInterObj);
            }

            // Check to see if object is a shop
            if (currentInterObjScript.shop)
            {
                currentInterObj.SendMessage("OpenShop");
            }

            // Check to see if object talks
            if (currentInterObjScript.talks)
            {
                // Tell the object to give its message
                currentInterObjScript.Talk();
            }

            // Do something with the object
            //currentInterObj.SendMessage("DoInteraction");
            currentInterObjScript.GenericInteraction();
        }

        // Use a food to heal yourself
        if (Input.GetButtonDown("Use item 1"))
        {
            if (playerData.CurrentHealth < playerData.MaxHealth)
            {
                // Check the inventory for food item
                GameObject food = inventory.FindItemByType("food");

                if (food != null)
                {
                    // Use the food - apply its effect
                    playerData.CurrentHealth = playerData.MaxHealth;

                    // Remove the food from the inventory
                    inventory.RemoveItem(food);
                }
            }
        }

        // Use powerup item
        if (Input.GetButtonDown("Use powerup"))
        {
            GameObject powerup = inventory.FindItemByType("powerup");

            if (powerup != null)
            {
                // Do something to players character
                Grow();


                // Remove from inventory
                inventory.RemoveItem(powerup);
            }
        }
    }