Forum rules - please read before posting.

Directly use item from inventory or from small sub menu

Hello everyone, first time posting but long time member!

I've recently started to shift from AGS to AGC and would really like to copy as much as I did on AGS over.

All my games are keyboard/ joystick controlled games.

What I'm trying to achieve is two of either things; either directly use an item straight from inventory if I'm in the proximity of a hotspot (stand on/next to hotspot, open inventory and just select the item and it runs the use process right away) or have a 2nd menu appear after I select an item from the inventory screen (use,look,combine) and handle those processes in there.

I'm aware that there may be scripting involved which is fine but I am completely new to Unity having only script experience in AGS

Any help would be greatly appreciated!

Comments

  • Welcome to the community, @Stranga.

    directly use an item straight from inventory if I'm in the proximity of a hotspot (stand on/next to hotspot, open inventory and just select the item and it runs the use process right away)

    This can be done with a custom script that hooks into the OnInventorySelect custom event, which is fired whenever an inventory item is selected, and then attempts to use it with the nearest Hotspot:

    using UnityEngine;
    using AC;
    
    public class AutoUseInventory : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnInventorySelect += OnInventorySelect; }
        private void OnDisable () { EventManager.OnInventorySelect -= OnInventorySelect; }
    
        private void OnInventorySelect (InvItem invItem)
        {
            Hotspot hotspot = KickStarter.player.GetComponentInChildren<DetectHotspots> ().NearestHotspot;
            if (hotspot)
            {
                hotspot.RunInventoryInteraction (invItem);
            }
        }
    
    }
    

    A tutorial on custom events can be found here.

    To use it, paste into a C# script named AutoUseInventory, and attach it to your Player. This needs your Player to have a Hotspot Detector component present on a child object. If you don't have one yet, create an empty child, and attach the Hotspot Detector, a Circle Collider that represents the boundary that Hotspots will be considered "nearby", and a Rigidbody2D with "Is Kinematic" checked.

    Once set up correctly, the script should check this detector's nearest Hotspot whenever an item is selected, and auto-use it with that Hotspot.

    have a 2nd menu appear after I select an item from the inventory screen (use,look,combine) and handle those processes in there.

    Setting the Settings Manager's Interaction method field to Choose Hotspot Then Interaction causes an Interaction menu to appear whenever a Hotspot or item is clicked - see the 2D Demo for an example.

    By default, this is limited to Hotspots. To enable such menus for Inventory items, set the Inventory interactions field to Multiple in the Settings Manager's "Inventory settings" panel.

  • Thank you so much, Chris! This is exactly everything I need now to convert everything I've done in AGS to AGC!

    Note: I also added a little more to the code to close the inventory and deselect the item after use, hope this is ok, it shouldn't break anything, right?

    using UnityEngine;
    using AC;
    
    public class AutoUseInventory : MonoBehaviour
    {
        private void OnEnable() { EventManager.OnInventorySelect += OnInventorySelect; }
        private void OnDisable() { EventManager.OnInventorySelect -= OnInventorySelect; }
    
        private void OnInventorySelect(InvItem invItem)
        {
            Hotspot hotspot = KickStarter.player.GetComponentInChildren<DetectHotspots>().NearestHotspot;
            if (hotspot)
            {
                AC.PlayerMenus.GetMenuWithName("Inventory").TurnOff();// Close the Inventory menu(s)
                hotspot.RunInventoryInteraction(invItem);
                KickStarter.runtimeInventory.SetNull();//Deselects item after use
    
            }
        }
    }
    
  • No, that should be fine.

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.