Forum rules - please read before posting.

Drop an object on Player from Inventory

124»

Comments

  • Use this script to only enable the Hotspot when an inventory item is selected:

    using AC;
    using UnityEngine;
    
    public class InventoryOnlyHotspot : MonoBehaviour
    {
    
        public Hotspot hotspot;
    
        private void OnEnable ()
        { 
            EventManager.OnInventorySelect += OnInventorySelect;
            EventManager.OnInventoryDeselect += OnInventoryDeselect;
        }
    
        private void OnDisable ()
        { 
            EventManager.OnInventorySelect -= OnInventorySelect;
            EventManager.OnInventoryDeselect -= OnInventoryDeselect;
        }
    
        private void OnInventorySelect (InvItem item)
        {
            hotspot.TurnOn ();
        }
    
        private void OnInventoryDeselect (InvItem item)
        {
            hotspot.TurnOff ();
        }
    
    }
    

    Plus, can i set Unity UI prefab menus to not get in the way of hotspots?

    Clicks on AC buttons will override the click behaviour on the scene underneath them.

  • Getting this error:

    Assets/Sleepytime Village/Scripts/InventoryOnlyHotspot.cs(2,1): error CS1529: A using clause must precede all other elements defined in the namespace except extern alias declarations

    Plus, do I just attach this to to the child with hotspot on of player?

  • Did you replace the script file's entire contents with the above?

    Once compiled, yes - attach it to the Hotspot and assign that Hotspot in its Inspector.

  • edited January 2022

    okay so compiles but the hotspots behind Rufus are not accessible, so so doesn't seem to work. The interaction source is set to Asset File if that makes any difference?

    See video here:

    https://www.dropbox.com/s/wvd7uswvcwwy5gx/Hotspotissue.mov?dl=0

  • using AC;
    using UnityEngine;
    
    public class InventoryOnlyHotspot : MonoBehaviour
    {
    
        public Hotspot hotspot;
    
        private void OnEnable ()
        { 
            EventManager.OnInventorySelect += OnInventorySelect;
            EventManager.OnInventoryDeselect += OnInventoryDeselect;
            hotspot.TurnOff ();
        }
    
        private void OnDisable ()
        { 
            EventManager.OnInventorySelect -= OnInventorySelect;
            EventManager.OnInventoryDeselect -= OnInventoryDeselect;
        }
    
        private void OnInventorySelect (InvItem item)
        {
            hotspot.TurnOn ();
        }
    
        private void OnInventoryDeselect (InvItem item)
        {
            hotspot.TurnOff ();
        }
    
    }
    
  • OK, so this is all amazing, is there a way to disable this for a moment or per inventory object, OR give a certain hotspot priority over Rufus or per inventory object? I have an issue when Rufus is standing at the front of the screen and the hotspot is directly over him. The hotspot becomes impossible to click on as Rufus hotspot takes precedence.

    https://www.dropbox.com/s/88isff2a6gcq1dm/Hotspot Access.png?dl=0

  • A Hotspot's Position along the Z-axis will control its priority relative to other objects. If you move the Lamp's Hotspot closer to the camera than the Player's, it should take precedence.

    It is also possible to have the script only work for items that the Player has a valid interaction for:

    using AC;
    using UnityEngine;
    
    public class InventoryOnlyHotspot : MonoBehaviour
    {
    
        public Hotspot hotspot;
    
        private void OnEnable ()
        { 
            EventManager.OnInventorySelect += OnInventorySelect;
            EventManager.OnInventoryDeselect += OnInventoryDeselect;
            hotspot.TurnOff ();
        }
    
        private void OnDisable ()
        { 
            EventManager.OnInventorySelect -= OnInventorySelect;
            EventManager.OnInventoryDeselect -= OnInventoryDeselect;
        }
    
        private void OnInventorySelect (InvItem item)
        {
            if (hotspot.HasInventoryInteraction (item))
            {
                hotspot.TurnOn ();
            }
        }
    
        private void OnInventoryDeselect (InvItem item)
        {
            hotspot.TurnOff ();
        }
    
    }
    
  • Awesome thanks

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.