- Home /
UI Button Sounds Volume Increases when Mouse passes over
Like the title says. I have a MainMenu with UI buttons and sound effects, well, the effects sound and work just fine, but when I move my mouse over the buttons, the volume increases each time I enter a new button. Any Idea what this could be? I have 2 AudioSources and 2 Audio clips that are set in script to play certain sounds when you hover/click. Heres a piece of my Buttons script( controls button presses and audio for buttons):
public AudioSource hoverSource;
public AudioSource clickSource;
public AudioClip hoverClip;
public AudioClip clickClip;
public void onMouseEnter()
{
hoverSource.clip = hoverClip;
hoverSource.Play();
}
IEnumerator playGame(int SceneNumber)
{
clickSource.clip = clickClip;
clickSource.Play();
yield return new WaitForSeconds(clickSource.clip.length);
SceneManager.LoadScene(SceneNumber);
}
public void Play(int SceneNumber)
{
StartCoroutine(playGame(SceneNumber));
}
Answer by Pharaoh_ · Apr 26, 2016 at 06:48 PM
First of all, there should be one AudioSource on your UI. After all, the current system operates on Hover and Click. Two buttons cannot be hovered or clicked on at the same time (unless you have more than one inputs). Additionally, a click sound should replace a hover sound if it is still playing. Thus, simply attach one AudioSource to your Camera and play the respective sound. The sound source should have 2D spatial blend, given that it's UI. On a side note, having two methods taking the same parameter within the same class is overly redundant. You could use either a global variable for that (shouldn't matter, since you're loading a new scene) or pass the parameter to only one of these.
From your current code, I see no volume changes, so I suspect that multiple buttons play the same sound, which gives the illusion of high volume. This could be something going on in the part of the code you did not post or the OnMouseEnter() is called from multiple buttons simultaneously (in the case they overlap). Use Debug.Log and report the name of the button and hover to only one. If multiple names are reported, then you've got your answer. My recommendation is to fix the single audio source for the time being and then provide further details.
P.S. I am surprised how onMouseEnter() is called. I could have sworn that it is case-sensitive and should be OnMouseEnter().
Your answer
![](https://koobas.hobune.stream/wayback/20220612075641im_/https://answers.unity.com/themes/thub/images/avi.jpg)