Sounds

How to play sounds for Inventool.

Sounds can be handled entirely with Events. The example below teaches you how you can play your own audio clips when an Inventool button is clicked.

Note that Inventool's UI was created with the UI Toolkit, so the Button class is from the UnityEngine.UIElements namespace and not the UnityEngine.UI namespace.

using Esper.Inventool.UI;
using UnityEngine;
using UnityEngine.UIElements;

public class SoundEventExample : MonoBehaviour
{
    [SerializeField]
    private AudioClip myAudioClip;

    private void Start()
    {
        // Register the callback
        InventoolWindow.Instance.onButtonClicked.AddListener(OnButtonClicked);
    }

    /// <summary>
    /// Plays a sound.
    /// </summary>
    /// <param name="button">The button that was clicked.</param>
    private void OnButtonClicked(Button button)
    {
        // Play the audio clip
        AudioSource.PlayClipAtPoint(myAudioClip, transform.position);
    }
}

Last updated