Forum rules - please read before posting.

What's a good way of structuring "if item is used with hotspot"?

edited June 2018 in Technical Q&A
Hey there folks,

In my game the player fires objects out as a projectile, which includes anything in their inventory.

What I want to do is setup some scene items (for instance a door hotspot in the scene) to recieve and react when different objects hit it. For instance, if the player fires a key object at it, the door opens, but, if the player fires a box of chocolates out, then a different response occurs.

I'm trying to figure out how best to structure this. Is this something which is possible in an actionList? To query what object is coming into contact with a hotspot? Or, does AC provide a inbuilt way for handling 'use inventory item with scene object?'

In my case, the object the player fires isn't actually a pure inventory item, it's the linked prefab which can be attached to a inventory item.


Many thanks,
Tem

Comments

  • Inventory interactions with Hotspots are normally configured within the Hotspot's Inspector.  At the bottom, you have an "Inventory interactions" section - which allows you to define an interaction as well as an associated inventory item.  "Fallback", or "Unhandled" interactions for unspecified items can also be defined here.

    To trigger this interaction through script, use:

    myHotspot.RunInventoryInteraction (2);

    Where "2" is replaced with the ID number of the inventory item in question.  ID numbers are listed to the left of an item's label in the Inventory Manager.

    If you're looking to trigger this via an item's linked prefab, you'll have to attach some script to that prefab that records its associated item's ID number that you can retrieve to run the correct interaction.
  • Thanks Chris. I've got this working now.

    In my case, when I fire a object I capture a reference to its inventory ID:

     public int objectID;

        private void Start()
        {
            //When the object is created, give it a ID which matches its inventory slot
            objectID = InventorySelection.activeInventorySlot;
        }


    Then, I've added some extra stuff to hotspot objects to detect when they've been hit:

    private void OnTriggerEnter(Collider other)
        {
            //Check to see if the incoming object is a inventory projectile
            incomingObject = other.gameObject.GetComponent<HotspotTrigger>();

            //If it doesn't, then return. We don't care anymore.
            if (incomingObject == null) { return; }

            //Call the interaction on the hotspot which matches the incoming objectID
            hotspot.RunInventoryInteraction(incomingObject.objectID);
        }




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.