Forum rules - please read before posting.

Selecting Inventory items via number keys

I have a simple inventory menu that I would like to be able to select items from via number keys, how to do this easily? I think it would be great if Inventory: Select would have an option to select item from a specific slot, instead of a set item.

Comments

  • I think it would be great if Inventory: Select would have an option to select item from a specific slot, instead of a set item.

    That's a fair suggestion - I'll give it some thought.

  • In the meantime, something like this ought to do it:

    using UnityEngine;
    using AC;
    
    public class ItemSeletionKeys : MonoBehaviour
    {
         void Update ()
         {
            if (!KickStarter.stateHandler.IsInGameplay ()) return;
            AttemptSelect (0, KeyCode.Alpha1);
            AttemptSelect (1, KeyCode.Alpha2);
            AttemptSelect (2, KeyCode.Alpha3);
            // etc
         }
    
         void AttemptSelect (int index, KeyCode keyCode)
         {
            if (Input.GetKeyDown (keyCode))
            {
                InvInstance invInstance = KickStarter.runtimeInventory.PlayerInvCollection.GetInstanceAtIndex (index);
                if (InvInstance.IsValid (invInstance)) invInstance.Select ();
            }
         }
    
    }
    
  • Thanks Chris, works like a charm.

  • Would it be difficult to have a check for a specific item like the Healing Potion, which would be used instead of selected when pressing the number key?

  • Sorry, I don't follow.

    The Inventory: Check Action can be used to check for the presence of a particular item in the Player's inventory.

  • Never mind, I figured out a workaround! Thanks

  • Another problem, I'm shifting through the inventory items but the selection apparently always selects the item that is first in the inventory, I'd like it to select whatever is shown in the bottom 3 slots at any time.

    https://drive.google.com/file/d/1mw2QOIte59sKO0ZB0-oewWJfgfQSs6es/view?usp=sharing

  • I'm having trouble understanding the video - are you scrolling through the InventoryBox element to reveal different items?

    Since you posted this thread, I looked into how your original question might be done without the need for custom script.

    Rather than using Inventory: Select, the latest release now adds an option to the Menu: Select Action to simulate the clicking of a given menu element. This Action - unlike the script above - will account for any scrolling that's occured in the Inventory menu.

  • Yeah, that works a lot better, thanks!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.