Adventure Creator Wikia
Advertisement

This limits the amount of items you can add to your inventory from a container. Thanks to ChrisIceBox for the script & instructions. From the AC forum:

If you're using the default Container menu, select the ContainerItems element and set its Click behaviour to Select Item Only. Then select the PlayerInventory element and set its Inventory box type to Custom Script.

This script, added to the scene on an empty GameObject, should then let you limit how many items can be added to it:

using UnityEngine;

using AC;

public class LimitItemsFromContainer : MonoBehaviour

{

    public int maxItems = 5;

    private void OnEnable ()

    {

        EventManager.OnMenuElementClick += OnMenuElementClick;

    }

    private void OnDisable ()

    {

        EventManager.OnMenuElementClick -= OnMenuElementClick;

    }

    private void OnMenuElementClick (Menu menu, MenuElement element, int slot, int buttonPressed)

    {

        if (menu.title == "Container" && element.title == "PlayerInventory")

        {

            MenuInventoryBox inventoryBox = element as MenuInventoryBox;

            InvInstance selectedInstance = KickStarter.runtimeInventory.SelectedInstance;

            if (InvInstance.IsValid (selectedInstance))

            {

                int numItems = KickStarter.runtimeInventory.PlayerInvCollection.GetCount ();

                if (numItems < maxItems)

                {

                    KickStarter.runtimeInventory.Add (selectedInstance);

                }

            }

            else

            {

                InvInstance clickedInstance = inventoryBox.GetInstance (slot);

                if (InvInstance.IsValid (clickedInstance))

                {

                    clickedInstance.Select ();

                }

            }

        }

    }

}

Advertisement