Forum rules - please read before posting.

Cursor SFX when dropping item on hotspot

Hi all

I want to have some sfx when I drop an inventory object on to a hotspot. In my game you click on the inventory item, move the cursor to the hotspot, then click again to use it. On both clicks I want some kind of effect, one when you click on the inventory item, one when you click on the hotspot to use it.

I can probably do that in the action list of that Use interaction (play a particle etc) but that would need to be done for each interaction.

Is there a single place where I can run an action list each time an object is successfully Use'd against a hotspot? I can see an actionlist for "Use on hotspot" but it's only for unhandled events. I want a global one for handled events, that will run before the specified interaction.

Will I have to code something here? In which case, any pointers as to which function is my friend?

Olly

Comments

  • edited May 2023

    Custom events are the way to approach this. Through scripting, such events can be used to run code whenever AC performs a common task.

    A tutorial on their usage can be found here.

    In this case, you'd likely want to hook into the events:

    Somethine along these lines should do it:

    using UnityEngine;
    using AC;
    
    public class InventoryAudio : MonoBehaviour
    {
    
        public AudioClip audioClip;
        public Sound sound;
    
        void OnEnable ()
        {
            EventManager.OnInventorySelect += OnInventorySelect;
            EventManager.OnHotspotInteract += OnHotspotInteract;
        }
    
        void OnDisable ()
        {
            EventManager.OnInventorySelect += OnInventorySelect;
            EventManager.OnHotspotInteract += OnHotspotInteract;
        }
    
        void OnInventorySelect (InvItem invItem)
        {
            sound.Play (audioClip);
        }
    
        void OnHotspotInteract (Hotspot hotspot, AC.Button button)
        {
            if (button != null && hotspot.GetButtonInteractionType (button) == HotspotInteractionType.Inventory)
            {
                sound.Play (audioClip);
            }
        }
    
    }
    
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.