Forum rules - please read before posting.

Menu Hover sound when using direct control (keyboard/mouse) + Unity UI

AC: 1.71.8 Unity: 2018.4.1f1

Hey, I've noticed that menu hover sounds assigned in the AC menu manager do not play when using direct control and a Unity UI canvas for the menu.

The sounds do play however when the mouse is hovered over these menu items.

I've attempted to make a script to detect when a menu button is highlighted and play a set sound. I'm not able to get this working, for one it needs an audio source set and the menu is a prefab so I can't reference scene objects.

Secondly I've tried attaching the script to an empty scene object (so I'm able to assign a audio source) but it doesn't seem to work there either.

Here's my script, which is probably full of problems:

using UnityEngine;
using AC;

public class ButtonHoverSound : MonoBehaviour
{
public string MenuName;
public string ElementName;

private void OnEnable() { EventManager.OnMouseOverMenu += OnMouseOverMenu; }
private void OnDisable() { EventManager.OnMouseOverMenu -= OnMouseOverMenu; }
[SerializeField] AudioSource yourAudioSource; // Better if you make this a static object eventually?
[SerializeField] AudioClip audioClipToPlay;

private void OnMouseOverMenu(Menu menu, MenuElement element, int slot)
{
    if (menu.title == MenuName && element != null && element.title == ElementName)
    {
        yourAudioSource.clip = audioClipToPlay;
        yourAudioSource.volume = 1;
        yourAudioSource.Play();
    }
}

}

Ideally the script would need to reference an audio source in the same way that the default menu hover sound functionality does, so this can be used independent of a scene audio source. I'm not sure how to do that though!

Any insight would be appreciated! Thanks.

Comments

  • v1.72.0 included the following:

    • Fixed: Hover sounds not playing when directly-navigating Unity UI menus

    Try the latest release and see if that addresses it.

  • Hi Chris, I've updated to v1.72.3 and I'm still having trouble with the hover sounds when directly navigating the menu.

    Here's my menu settings:

    I wonder if it could have anything to do with me using the Navigation - Explicit setting in the Unity UI prefab? The menu is also displayed in world space, fyi.

  • As it's not set to pause the game, I take it you're using the Engine: Manage systems Action to allow for direct-navigation during gameplay? And you've defined a Default Sound in the Scene Manager?

    All looks fine to me - and trying similar settings on my end doesn't cause an issue.

    If you pause your game when the Menu is on, do your Buttons have UI Slot Click components attached? They should be added on automatically at runtime.

  • Yeah default sound is assigned in this scene (the title screen) and I'm using direct-navigation during gameplay for menus.

    The menu for pausing the game has a similar setup, is set to pause the game when enabled and has the same issue.

    I've set this menu 'Title' to pause the game when enabled and the UI Slot Click components are attached but still no hover sound.

    Might be worth noting that the click sounds work it's just the hover sounds that don't.

    I will do some further tests and post back with any findings.

  • Be aware that - for menu sounds to play while paused - Play while game paused? needs to be checked in your Default Sound Inspector.

    You're welcome to PM me a .unitypackage file to test. It would need to include your 8 Manager asset files, the Title menu UI prefab and the hover sound AudioClip asset.

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.