- Home /
Music skips when playing sound effects
In the main menu of my game, I want the buttons to make sounds when selected and clicked. The sound effects that play when buttons are selected work fine. However, when a button is clicked that moves to a different section of the menu (which is just another Canvas), the music that's playing on the Main Camera skips forward a little bit then jumps back to where it was before. Here is the script that plays the button sound effects:
public class ResponsiveMenuButton : MonoBehaviour, ISelectHandler
{
[SerializeField] private AudioClip selectClip;
[SerializeField] private AudioSource soundPlayer;
[SerializeField] private AudioClip clickClip;
public void OnSelect(BaseEventData eventData)
{
if (PlayerPrefs.HasKey("sound"))
{
soundPlayer.PlayOneShot(selectClip, PlayerPrefs.GetFloat("sound"));
}
else
{
soundPlayer.PlayOneShot(selectClip, 0.3f);
}
}
public void OnClick()
{
if(PlayerPrefs.HasKey("sound"))
{
soundPlayer.PlayOneShot(clickClip, PlayerPrefs.GetFloat("sound"));
}
else
{
soundPlayer.PlayOneShot(clickClip, 0.3f);
}
}
}
The next section of the menu is loaded by making the current menu Canvas inactive and making the next menu Canvas active. The AudioSource that plays sound effects is different from the AudioSource that plays music.
Answer by hiineededaname · Nov 01, 2021 at 06:18 PM
Turns out there was some weird issue that happened while I was importing the AudioClip that caused it to mix some of the sounds together, creating the effect. I'm a bit worried as to why that happened but I re-imported the clip and the issue is solved.
Answer by Betina_art · Nov 01, 2021 at 03:05 PM
Hi! Check out this vid by Brackeys on making an Audio Manager: https://www.youtube.com/watch?v=6OT43pvUyfY
He also includes the code for the audio manager.
The method that Brackeys uses in this video would be infeasible with the layout of my game. Thanks for trying to help, though!
How about getting the WWise plugin? You can use it for managing multiple tracks and also transitioning music to same timestamps in the audio, etc. There's a video on it in unity's official tutorials