Forum rules - please read before posting.

Run action after dragging item to inventory

Is there a way to trigger an action list asset after an inventory item is dragged from a container to the players inventory? It would be sort of like a combine event but with the inventory.

Comments

  • You should be able to do this using custom events.

    When an item is taken from a container, it is automatically placed in the player's inventory.  At this time, OnContainerRemove is triggered, which you can use to access both the Container that was affected, and the item that was taken.

    To see an example, place this code in a script named "InventoryEventTest", and attach to a GameObject in your scene:

    using UnityEngine;
    using System.Collections;
    using AC;

    public class InventoryEventTest : MonoBehaviour
    {

      public ActionListAsset myActionListAsset;

      private void OnEnable ()
      {
        EventManager.OnContainerRemove += OnContainerRemove;
      }
       
      private void OnDisable ()
      {
        EventManager.OnContainerRemove -= OnContainerRemove;
      }
       
      private void OnContainerRemove (Container container, ContainerItem containerItem)
      {
        Debug.Log ("Item " + containerItem.GetLinkedInventoryItem ().label + " was removed from " + container.name);
          myActionListAsset.Interact ();   
      }
       
    }

    Then see the Console update when you remove items.

    To trigger an ActionList asset, you just need to call its Interact function.
  • Great that is just what I was looking for. Much thanks! =D>
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.