Forum rules - please read before posting.

Combine Inventory Items using separate keyboard key?


In my game (keyboard/controller, unity 5.6.0, AC 1.56g ) I open inventory with space bar, navigate with arrows and select items with E, examine with Q. Now, I've set it up so by selecting an item the menu turns off leaving a player with an item displayed above their head, so they can use it on hotspots. If you want to use inventory on inventory - you have to press space again to open inventory again and then use it. The thing is, I want to add separate button (say "c") to select an item BUT keep the inventory open.

How would I go about it? I've spent an entire day trying different things (active inputs etc) but got NOWHERE...

Please help me guys... ;)

Comments

  • Probably easiest with a custom script to respond to the correct keypress, but before that you'd have to get the right behaviour when the key is pressed.

    Forgetting about selecting and closing the menu for the moment, and just focusing on the combining behaviour - is that working how you intend?  Presumably just selecting the item without closing the Menu is what you're looking for.
  • The combining is fine. All I need is what I'd call "InteractionC" to work. Tried to make it myself, but I just couldn't figure out how to make different button run AC action. A simple variable change back and forth would do the trick - as I could then check in inventory actions whether it's being used or combined...


  • What I'm getting at is: is merely selecting the item and not closing the menu all you're looking to do?  I'll see about writing the thing for you, but I need to know exactly it is you want.
  • Made a little video to show you exactly what I mean ;)


  • Paste this in a C# script named CombineInventoryButton.cs, and add it to your scene:

    Define an input named "Combine" in your Input settings, and the script'll select the hovered item when it's pressed.

  • Thanks, Chris ;)

    It brought up an error at first. "SelectedItem" part of code didn't like the capital "S" so I changed it to "selectedItem" and it works now exactly how I wanted it to;)

    (it's probably because I'm still working with a pretty old version of AC & unity)

    Dude, as always - huge thanks. You're the new CJ ;) Keep up the good work!
  • Oh, I put that script on GameEngine. I'm assuming that's all right, since it works in all scenes and there is no smoke coming out of my computer ;)
  • One more thing... Sorry about TRIPLE posting. But if I wanted to add audio clip to play on selecting inventory item, what would that be?...
  • Declare an audio clip as an exposed variable:

    public AudioClip myAudioClip

    Then you can play it when you want through script:

    AudioSource.PlayClipAtPoint (myAudioClip, KickStarter.mainCamera.transform.position);
  • Is there a chance this script could be re-uploaded Chris? The link is dead and I would also like to have a specific 'combine' keyboard button. Thanks~!

  • using UnityEngine;
    using System.Collections;
    using AC;
    
    public class CombineInventoryButton : MonoBehaviour
    {
    
        public string combineInput = "Combine";
        public string inventoryMenu = "Inventory";
    
    
        private void Update ()
        {
            // Check for input
            if (Input.GetButtonDown (combineInput))
            {
                // Check the menu is open
                if (PlayerMenus.GetMenuWithName (inventoryMenu).IsOn ())
                {
                    // Check we've no item selected
                    if (KickStarter.runtimeInventory.SelectedItem == null)
                    {
                        // Check we're hovering over an item
                        if (KickStarter.runtimeInventory.hoverItem != null)
                        {
                            // Select the item
                            KickStarter.runtimeInventory.SelectItem (KickStarter.runtimeInventory.hoverItem);
                        }
                    }
                }
            }
        }
    
    }
    
  • Thanks Chris!

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.