Forum rules - please read before posting.

Disable inventory interaction for specific hotspots

Is it possible to disable inventory interactions for specific hotspots? I.e. such that if an inventory item is active (such that the cursor is currently that item) and you hover over the hotspot, it simply won't react in any way (no updating of hotspot label, etc.).

At the moment I need this primarily for hotspots that represent doors. I'd like for my doors to be 'Single interaction' hotspots that perform a 'Switch scene' action when clicked, and that this is the only interaction available whatsoever for those hotspots.

Comments

  • edited March 18

    Is there a pattern to this? Would it be to disable all single-use Hotspots, whenever any inventory item is selected?

    You could do it by hooking into the OnInventorySelect and OnInventoryDeselect custom events - and disabling/enabling such Hotspots.

    Something like this:

    using UnityEngine;
    using System.Collections;
    using AC;
    
    public class AutoDisableSingleHotspots : MonoBehaviour
    {
    
        private void OnEnable ()
        {
            EventManager.OnInventorySelect += OnSelectInventory;
            EventManager.OnInventoryDeselect += OnDeselectInventory;
        }
    
        private void OnDisable ()
        {
            EventManager.OnInventorySelect -= OnSelectInventory;
            EventManager.OnInventoryDeselect -= OnDeselectInventory;
        }
    
        private void OnSelectInventory (InvItem _item)
        {
            foreach (Hotspot hotspot in AllHotspots)
            {
                if (hotspot.IsSingleInteraction ())
                {
                    hotspot.TurnOff ();
                }
            }
        }
    
        private void OnDeselectInventory (InvItem _item)
        {
            foreach (Hotspot hotspot in AllHotspots)
            {
                if (hotspot.IsSingleInteraction ())
                {
                    hotspot.TurnOn ();
                }
            }
        }
    
        private Hotspot[] AllHotspots
        {
            get
            {
                return FindObjectsOfType <Hotspot>();
            }
        }
    
    }
    
  • Thank you! I'll take a look at this. Although at this point I'm not completely sure if it should apply to all Single interaction hotspots, I can probably figure out some kind of pattern. As for the script, which element should I apply that to?

  • You can adapt the script to expose the exact Hotspots you want to apply it to.

    Just attach it to an empty GameObject in your scene.

  • Right, so I need this script to be present in every scene that it should apply to?

  • Yes. You can attach it to your GameEngine prefab to automate this.

  • Ah yes, thank you! I had just applied a DontDestroyOnLoad() to the script, but it's probably safer to simply attach it to the GameEngine.

    In case others want to make use of this thread, let me just point out a typo in the script: in the OnDeselectInventory() function it should be 'hotspot.TurnOn()' instead of .TurnOff() :)

  • Quite right - fixed.

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.