Forum rules - please read before posting.

Make Player a Hotspot for Inventory Items (Equip Inventory Item)

I am doing the Unity Adventure Game tutorial and making small improvements to learn Adventure Creator.

When the player picks up the glasses, I don't have her equipping the inventory item automatically. Instead, the player must select this from the inventory and then click on the themselves (Player character) in order for the ActionList to begin in which she equips the glasses.

What are some best practices for this, should I use a Hotspot / Trigger etc, and how to handle the Text that is displayed in this situation when hovering the mouse?

For example, if the glasses are selected from the inventory and the the mouse is hovering over the player, instead of displaying "Use Glasses On Player" could some other text be used such as "Equip Glasses"?

Thank you

Comments

  • The "Use X on Y" syntax used by inventory items can be set on a per-item basis in the Inventory Manager by checking Override 'Use' syntax? in their list of properties.  If the "Use" is "Equip", "on" is "Y" and the Player's Hotspot label is a single space, it should say "Equip Glasses".

    Another thing to keep in mind is that your Player's Hotspot should have its Interaction source field set to Asset File, so that it runs ActionList assets when interacted with.  This way, you can run the same Actions regardless of which scene you're in.
  • - I've attached a Hotspot to the player and also a RememberHotspot script.
    - I've set "Hotspot state on start" to OFF

    I only want the player's hotspot to become active if an Inventory Item is selected, as it normally does not make sense to click on myself. 

    Question 1:
    Is it possible to call an ActionList when an Inventory item is Selected (upon cursor icon change)?

    Question 2:
    I have used the "Override 'Use' Syntax option in the Inventory Manager to change the text to "Equip Glasses".

    However, now when I hover the glasses over CoffeeBot, I still see "Equip Glasses". I only want to override 'Use' syntax when hover over specific Hotspot (the player's). Is that possible?
  • Is it possible to call an ActionList when an Inventory item is Selected (upon cursor icon change)?

    You can define a "Use" interaction for an item in the Inventory Manager, which will run when left-clicked.  That will override the default behaviour of it becoming selected, but you can select it manually by ending your ActionList with the Inventory: Select Action.

    However, you will still need to turn off the Hotspot when the item is no longer selected, so instead it's probably better to have a looping ActionList that runs in the background and enables/disables the Hotspot as necessary.

    The Inventory: Check selected Action can be used to determine if a given item is currently selected.  Following this up with two Hotspot: Enable or disable Actions that turn the player's Hotspot on/off accordingly, and then looping back onto the first Action will cause it to continually check.  You must also, however, insert an Engine: Wait Action before looping to prevent it looping instantly (causing a crash).  Here's an example using the 3D Demo's assets:

    https://imgur.com/a/YqvW4

    Put these Actions into an ActionList asset, and set the asset's When running field to Run In Background so that it doesn't interfere with gameplay.  You'll have to run it from your scene's "On start" Cutscene using the ActionList: Run Action.

    Of course, it's also possible (and may be easier, depending on experience) to just do it through scripting.  AC's custom events system (see Section 12.3 of the Manual) allows you to easily run custom code when AC performs common tasks.

    It should be possible to enable/disable the Hotspot using OnInventorySelect and OnInventoryDeselect events to run the Hotspot's TurnOn and TurnOff methods.

    I only want to override 'Use' syntax when hover over specific Hotspot (the player's). Is that possible?

    It is, but this time only through coding.  This time, you'd want to use the OnHotspotInteract event to change the item's syntax when hovering over the player's Hotspot.  To get an API reference to any Manager field, just right-click on its label.  Then again, if the previous answer solves the issue this may be unnecessary.

    If you'd like help with scripting, just say.
  • Huge thanks, I went ahead and just will use custom scripting. Here's a custom script which will enable the player's hotspot only when an inventory item is selected:

    using AC;
    public class HotspotControl : MonoBehaviour {
    private Hotspot myHotspot;

    void Start () {
    myHotspot = GetComponent();
    EventManager.OnInventorySelect += InventoryItemSelected;
    EventManager.OnInventoryDeselect += InventoryItemDeselected;
    }

    private void InventoryItemSelected(InvItem item) {
    myHotspot.TurnOn();
    }

    private void InventoryItemDeselected(InvItem item) {
    myHotspot.TurnOff();
    }
    }
  • Nice one.  The forum does sometimes have trouble when posting angle brackets, so the GetComponent function didn't paste right - but there is a community wiki here if you'd ever like to contribute custom scripts.
  • edited December 2017
    "It is, but this time only through coding.  This time, you'd want to use the OnHotspotInteract event to change the item's syntax when hovering over the player's Hotspot."

    Unless I'm making a mistake, there are no events triggered when HOVERING over a hotspot. In my case, I want to change the words that display when a certain Inventory Item is selected and over a certain hotspot.

    For example, the sword should say "Use 'sword' on 'tree'" normally. But if I am hovering over the player's hotpot, I want the text to just say "Equip sword".

    For this case, I think I can achieve the desired result via OnInventorySelect and OnInventoryDeselect and changing the value of InvItem.hotspotPrefix1 and InvItem.hotspotPrefix2 

    However, how do I know hotspot the cursor is currently hovering over? I only want to change the text when the cursor is hovering over the player's hotspot.
  • That should be the OnHotspotSelect event.

    You can also assign a Higlight component to the Hotspot that can trigger events when highlighted / unhighlighted.  You can uncheck Auto-brighten materials? on the Highlight component to prevent any automatic visual effect.
  • Thank you! I was able to get it working like this:
    EventManager.OnHotspotSelect += OnHotspotSelect;
    private void OnHotspotSelect(Hotspot hotspot) {
            if (hotspot.name == "Player") {
                if (KickStarter.runtimeInventory.SelectedItem != null) {
                    string currentSelectedItem = KickStarter.runtimeInventory.SelectedItem.label;
                    if (currentSelectedItem == "Sword" || currentSelectedItem == "Helmet") {
                        UpdateItemHoverText(KickStarter.runtimeInventory.SelectedItem, "Equip", "");
                        hotspot.SetName(" ", 0);                    

    Tutorial:

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.